I can retrieve public folders stored in specific Public folder mailbox using this powershell command:
Get-PublicFolder –GetChildren | Where { $ _.ContentMailboxName –eq “PFMailbox1” }
(But I don't want to use remote PowerShell)
I'm not able to do this using EWS.
My first idea was to get all public folders and then sort them according Public folder mailboxes.
But there is probably no Extended MAPI property which contains public folder mailbox name (similar to ContentMailboxName powershell property).
So I tried this: EWS with delegate access
var mailbox = new Mailbox("PFMailbox1@MyDomain.local");
// PFMailbox1 is Public Folder mailbox with Pubclic folders
FolderId folderId = new FolderId(WellKnownFolderName.MsgFolderRoot, mailbox);
Folder rootfolder = Folder.Bind(service, folderId);
(WellKnownFolderName property was tested with .Root and PublicFolderRoot too)
but I always get error:
"The request failed. The remote server returned an error: (503) Server Unavailable." or "An unhandled exception of type 'Microsoft.Exchange.WebServices.Data.ServiceResponseException' occurred in Microsoft.Exchange.WebServices.dll"
When I tried impersonation
service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, impUser);
// impUser=PFMailbox1@MyDomain.local
Folder rootfolder = Folder.Bind(service, WellKnownFolderName.MsgFolderRoot );
I get error:
"The account does not have permission to impersonate the requested user."
All mailbox permission for user Administrator and PFMailbox1 are set to full access. I'm using latest Exchange2013 dll's.
EDIT1:
Second issue is how to create root public folder and save it to desired public folder mailbox?
EWS method Folder.Save(FolderId) has only one parameter and if I use FolderId = PublicFolderRoot -> all folders will be saved into MasterHierarchy Public Folder Mailbox (mailbox which was first created).
The only solution I know is to create first level (root) folders using Remote Power Shell for every Public Folder Mailbox.
New-PublicFolder "Folder1" -Mailbox "PFMailbox1"
New-PublicFolder "Folder2" -Mailbox "PFMailbox2"
and then on second (third,..) folder level I can use Folder.Save(FolderID). But how to do it using EWS ?