在MessageComposeCommandSurface中通过EWS获取回复邮件附件的SOAP请求异常
解决MessageCompose场景下通过SOAP请求获取会话邮件附件的问题
问题根源
你的SOAP请求返回收件箱所有内容,核心原因是过滤条件未正确生效——要么是ConversationId的格式未匹配EWS要求,要么是Restriction节点的过滤逻辑写错了。
正确实现步骤
确认ConversationId格式适配EWS
Office.context.mailbox.item.conversationId返回的是Base64编码的EWS标准ID,直接填入SOAP请求的对应节点即可,无需额外转码,但要确保包裹在<ConversationId>或过滤条件的Constant值中。编写带精准过滤的SOAP请求
使用EWS的FindItem操作锁定指定会话的邮件,再通过GetAttachment下载附件,以下是完整示例:
第一步:定位会话内的目标邮件(FindItem请求)
<?xml version="1.0" encoding="utf-8"?> <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_SP1" /> </soap:Header> <soap:Body> <m:FindItem Traversal="Shallow"> <m:ItemShape> <t:BaseShape>IdOnly</t:BaseShape> <t:AdditionalProperties> <t:FieldURI FieldURI="item/Attachments" /> <t:FieldURI FieldURI="item/ItemClass" /> </t:AdditionalProperties> </m:ItemShape> <m:Restriction> <t:IsEqualTo> <t:FieldURI FieldURI="item/ConversationId" /> <t:FieldURIOrConstant> <t:Constant Value="YOUR_CONVERSATION_ID_HERE" /> </t:FieldURIOrConstant> </t:IsEqualTo> </m:Restriction> <m:ParentFolderIds> <t:DistinguishedFolderId Id="inbox" /> </m:ParentFolderIds> </m:FindItem> </soap:Body> </soap:Envelope>
- 替换
YOUR_CONVERSATION_ID_HERE为你获取到的conversationID值。 Traversal="Shallow"限定只搜索收件箱根目录,避免返回子文件夹内容;通过ItemClass可进一步筛选出原始邮件(值为IPM.Note)。
- 下载目标邮件的附件(GetAttachment请求)
从FindItem返回结果中提取带附件的邮件ID,再获取对应附件ID,发送如下请求:
<?xml version="1.0" encoding="utf-8"?> <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_SP1" /> </soap:Header> <soap:Body> <m:GetAttachment> <m:AttachmentIds> <t:AttachmentId Id="YOUR_ATTACHMENT_ID_HERE" /> </m:AttachmentIds> </m:GetAttachment> </soap:Body> </soap:Envelope>
- 替换
YOUR_ATTACHMENT_ID_HERE为从FindItem结果中拿到的附件ID。
额外提示
- 若你需要的是正在编辑的回复草稿中的附件,无需走SOAP流程,直接尝试调用
Office.context.mailbox.item.attachments——部分新版本Outlook客户端已支持在Compose场景下访问该属性。 - 所有EWS请求必须通过
Office.context.mailbox.makeEwsRequestAsync方法发送,确保插件身份验证生效,避免权限报错。
内容的提问来源于stack exchange,提问作者user27018791
相关产品推荐
相关产品推荐

