Search code examples
outlookoffice365exchangewebservices

How to list public folder mailboxes via EWS?


I cannot find any solution to properly list all public folder mailboxes and public folders using SOAP api. I found only powershell commands or C# methods. If anybody know how to get/list all public folders, please provide me with the solution.


Solution

  • To enumerate Public Folders you need to use the FindFolder operation and then make a Shallow traversal query of each folder level starting at the Root (because you can't do deep traversals) eg

        <?xml version="1.0" encoding="utf-8"?>
        <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
        xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
        <soap:Body>
            <FindFolder Traversal="Shallow" xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
            <FolderShape>
                <t:BaseShape>Default</t:BaseShape>
            </FolderShape>
            <ParentFolderIds>
                <t:DistinguishedFolderId Id="publicfoldersroot"/>
            </ParentFolderIds>
            </FindFolder>
        </soap:Body>
        </soap:Envelope>
    

    You can't get Public folder Mailboxes using EWS what you should be doing on Office365 is discovering the correct PublicFolder Mailbox to include in the routing headers so you should read through https://learn.microsoft.com/en-us/exchange/client-developer/exchange-web-services/how-to-route-public-folder-hierarchy-requests and https://learn.microsoft.com/en-us/exchange/client-developer/exchange-web-services/how-to-route-public-folder-content-requests (which both have XML samples for the calls you need).