通过EWS发送邮件时如何获取保存发送副本的ItemId

dka*_*arp 2 email exchangewebservices office365

EWS文档说,要发送消息并将副本保存到“已发送邮件”文件夹中,应将CreateItem操作与MessageDisposition值为SendAndSaveCopy一起使用

   <m:CreateItem MessageDisposition="SendAndSaveCopy">
     <m:SavedItemFolderId>
       <t:DistinguishedFolderId Id="sentitems" />
     </m:SavedItemFolderId>
     <m:Items>
       <t:Message>
         <t:Subject>Company Soccer Team</t:Subject>
         <t:Body BodyType="HTML">Are you interested in joining?</t:Body>
         <t:ToRecipients>
           <t:Mailbox>
             <t:EmailAddress>sadie@contoso.com </t:EmailAddress>
           </t:Mailbox>
         </t:ToRecipients>
       </t:Message>
     </m:Items>
   </m:CreateItem>
Run Code Online (Sandbox Code Playgroud)

成功时,“服务器用CreateItemResponse消息响应CreateItem请求,该消息包括ResponseCode值NoError(表示电子邮件已成功创建)和新创建的消息的ItemId。”

在Office 365上使用EWS,这几乎可以成功进行。消息已发送,副本已保存到“已发送邮件...”,但响应中返回已保存副本的ItemId :

   <m:CreateItemResponse>
     <m:ResponseMessages>
       <m:CreateItemResponseMessage ResponseClass="Success">
         <m:ResponseCode>NoError</m:ResponseCode>
         <m:Items />
       </m:CreateItemResponseMessage>
     </m:ResponseMessages>
   </m:CreateItemResponse>
Run Code Online (Sandbox Code Playgroud)

有没有一种方法可以指导EWS服务器实际返回已保存副本的ItemId?另外,发送完成后查找保存副本的首选机制是什么?

dka*_*arp 5

显然,该文档是错误的或不适用的。这篇MSDN博客文章符合我的经验:SendAndSaveCopy CreateItem请求没有返回ItemId 。它提出以下建议:

Simply stamp your e-mail message with a custom extended property when you create the message, and then use that extended property to find the message in the Sent Items folder after it has been sent.

评论者建议不要使用昂贵的FindItems-with-SearchFilter调用来查找自定义属性标记的保存副本,而应该执行以下操作:

1. Set your extended prop.

2. Do a FindItem with NO restriction against the sent items folder, SORTED by creation date descending with a indexed page view of about 5. Include your extended prop in the PropertySet.

3. Iterate across the results looking for your extended prop.