EWS api为什么返回ErrorNonExistentMailbox错误?

时间:2019-02-11 16:57:27

标签: outlook office365 exchangewebservices

我在Office 365租户中有几个用户帐户,并分配了许可证。当我尝试使用FindFolder operation从包含下一个正文的EWS API中获取用户邮箱中的信息(例如所有文件夹和项目)时:

<?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:Header>
    <t:RequestServerVersion Version="Exchange2013"/>
    <t:ExchangeImpersonation>
      <t:ConnectingSID>
        <t:PrincipalName>name.surname@mydomain.be</t:PrincipalName>
      </t:ConnectingSID>
    </t:ExchangeImpersonation>
  </soap:Header>
  <soap:Body>
    <FindFolder xmlns="http://schemas.microsoft.com/exchange/services/2006/messages" Traversal="Shallow">
      <FolderShape>
        <t:BaseShape>AllProperties</t:BaseShape>
      </FolderShape>
      <IndexedPageFolderView MaxEntriesReturned="1000" BasePoint="Beginning" Offset="0"/>
      <ParentFolderIds>
        <t:DistinguishedFolderId Id="msgfolderroot"/>
      </ParentFolderIds>
    </FindFolder>
  </soap:Body>
</soap:Envelope>

(name.surname@mydomain.be是目标Office 365帐户的用户主体名称),我收到下一个正文的错误回复:

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header>
    <h:ServerVersionInfo MajorVersion="15" MinorVersion="20" MajorBuildNumber="1601" MinorBuildNumber="24" Version="V2018_01_08" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
  </s:Header>
  <s:Body>
    <m:FindFolderResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
      <m:ResponseMessages>
        <m:FindFolderResponseMessage ResponseClass="Error">
          <m:MessageText>Mailbox does not exist.</m:MessageText>
          <m:ResponseCode>ErrorNonExistentMailbox</m:ResponseCode>
          <m:DescriptiveLinkKey>0</m:DescriptiveLinkKey>
        </m:FindFolderResponseMessage>
      </m:ResponseMessages>
    </m:FindFolderResponse>
  </s:Body>
</s:Envelope>

GetFolder operation也给我相同的结果。

此错误通常是由未经许可的邮箱帐户引起的。但是我所有的用户都有有效的Exchange许可证。为什么我会收到这样的ErrorNonExistentMailbox错误响应?

2 个答案:

答案 0 :(得分:0)

确保运行EWS脚本的帐户具有ApplicationImpersonation权限。因此,在这种情况下,您的帐户应具有ApplicationImpersonation权限。

  • 在O365中导航到EAC>权限>将ApplicationImpersonation添加到HygeneManagement RBAC组,然后将自己添加为成员。 这应该可以解决问题。

将来,如果您想在ApplicationImpersonation上进行故障排除,则可以使用EXRCA(https://testconnectivity.microsoft.com/)> O365选项卡> Microsoft Exchange Web服务连接测试>选择“服务帐户访问(开发人员)”并运行测试。

让我知道您是否还有其他问题。

答案 1 :(得分:0)

使用交换服务时出现了此问题,邮箱在某些请求后禁止了请求(我不知道为什么?!)。 (对我来说有200个请求)