Search code examples
soapoutlooksoapuiexchange-serverexchangewebservices

Get folder List for a particular email using GetFolder operation from Exchange Web Service using SOAP Message


I am using SOAPUI for my test. We have a service account linked to multiple inboxes. I am using GetFolder Operation of Exchange Web Services, specifying the request Header with Email ID. It seems like EWS is ignoring the provided email ID into the Soap header and only returning default inbox (I am supplying shared inbox in the header, connected to service account that is being used in authentication). Kindly help to identify of my request is correct or Do i need to specify some flag to make sure my share inbox is accessible from my request?

Here is the sample request.

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
  <soap:Header>
   <t:ConnectingSID>
            <!--You have a CHOICE of the next 4 items at this level-->
            <t:PrincipalName>[email protected]</t:PrincipalName>
             <t:PrimarySmtpAddress>[email protected]</t:PrimarySmtpAddress>        
              <t:SmtpAddress>[email protected]</t:SmtpAddress>

         </t:ConnectingSID>
  </soap:Header>
  <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="msgfolderroot"/>
      </ParentFolderIds>
    </FindFolder>
  </soap:Body>
</soap:Envelope>



Solution

  • If the service account has access to the Mailbox in question then you need to use the Mailbox child node of DistinguishedFolderId to specify the Mailbox you want to access eg

    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
            xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"
            xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      <soap:Header>
        <t:RequestServerVersion Version="Exchange2013" />
      </soap:Header>
      <soap:Body>
        <m:GetFolder>
          <m:FolderShape>
            <t:BaseShape>AllProperties</t:BaseShape>
          </m:FolderShape>
          <m:FolderIds>
            <t:DistinguishedFolderId Id="inbox"><t:Mailbox><t:EmailAddress>[email protected]</t:EmailAddress></t:Mailbox></t:DistinguishedFolderId>
          </m:FolderIds>
        </m:GetFolder>
      </soap:Body>
    </soap:Envelope>
    

    The only time you would use ConnectingSID is when your using EWS impersonation (where you have those rights) and your impersonation header should look like

    <soap:Header>
      <t:ExchangeImpersonation>
        <t:ConnectingSID>
          <t:PrimarySmtpAddress>[email protected]</t:PrimarySmtpAddress>
        </t:ConnectingSID>
      </t:ExchangeImpersonation>
    </soap:Header>