如何使用托管的 EWS API 访问 Office 365 统一组?

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

我想使用 EWS 托管 SOAP API 访问 Office 365 统一组邮箱(也称为对话)中的文件夹和消息,但我找不到访问它的方法。

我尝试使用 https://graph.microsoft.com/v1.0/groups/<group-id>?$select=proxyAddresses 获得的 2 个地址访问邮箱的根文件夹,有和没有 SPO: 和 SMTP: 前缀,但其中 none 有效。

请求的格式如下:

<?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>

这是错误消息:

<?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>

不确定是否有更好的方法,但是选择一个普通的 Office 365 用户来模拟并告诉 API 打开另一个电子邮件地址的邮箱是可行的:

<?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>