Search code examples
exchangewebservicesoutlook-restapi

How do I access a Office 365 unified group's with the EWS managed API?


I want to access folders and messages in a Office 365 unified group's mailbox (aka conversations) with the EWS managed SOAP API, but I can't find a way to access it.

I tried accessing the mailbox's root folder with the 2 addresses obtained by https://graph.microsoft.com/v1.0/groups/<group-id>?$select=proxyAddresses, with and without the SPO: and SMTP: prefixes, but none of them worked.

The request was in the format below:

<?xml version="1.0"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages">
  <soap:Header>
    <t:RequestServerVersion Version="Exchange2013"/>
    <t:ExchangeImpersonation>
      <t:ConnectingSID>
        <t:SmtpAddress>group-name@tenant-name.onmicrosoft.com</t:SmtpAddress>
      </t:ConnectingSID>
    </t:ExchangeImpersonation>
  </soap:Header>
  <soap:Body>
    <GetFolder xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
      <FolderShape>
        <t:BaseShape>Default</t:BaseShape>
        <t:AdditionalProperties>
          <t:FieldURI FieldURI="folder:ParentFolderId"/>
        </t:AdditionalProperties>
      </FolderShape>
      <FolderIds>
        <t:DistinguishedFolderId Id="root"/>
      </FolderIds>
    </GetFolder>
  </soap:Body>
</soap:Envelope>

and this is the error message:

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Body>
        <s:Fault>
            <faultcode xmlns:a="http://schemas.microsoft.com/exchange/services/2006/types">a:ErrorNonExistentMailbox</faultcode>
            <faultstring xml:lang="en-US">The SMTP address has no mailbox associated with it.</faultstring>
            <detail>
                <e:ResponseCode xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">ErrorNonExistentMailbox</e:ResponseCode>
                <e:Message xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">The SMTP address has no mailbox associated with it.</e:Message>
                <t:MessageXml xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
                    <t:Value Name="SmtpAddress">group-name@tenant-name.onmicrosoft.com</t:Value>
                </t:MessageXml>
            </detail>
        </s:Fault>
    </s:Body>
</s:Envelope>

Solution

  • Not sure if there are better methods, but picking a normal Office 365 user to impersonate and telling the API to open another email address's mailbox works:

    <?xml version="1.0"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages">
      <soap:Header>
        <t:RequestServerVersion Version="Exchange2013"/>
        <t:ExchangeImpersonation>
          <t:ConnectingSID>
            <t:SmtpAddress>user@tenant-name.onmicrosoft.com</t:SmtpAddress>
          </t:ConnectingSID>
        </t:ExchangeImpersonation>
      </soap:Header>
      <soap:Body>
        <GetFolder xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
          <FolderShape>
            <t:BaseShape>Default</t:BaseShape>
            <t:AdditionalProperties>
              <t:FieldURI FieldURI="folder:ParentFolderId"/>
            </t:AdditionalProperties>
          </FolderShape>
          <FolderIds>
            <t:DistinguishedFolderId Id="inbox">
                <t:Mailbox>
                  <t:EmailAddress>group-name@tenant-name.onmicrosoft.com</t:EmailAddress>
                </t:Mailbox>
            </t:DistinguishedFolderId>
          </FolderIds>
        </GetFolder>
      </soap:Body>
    </soap:Envelope>