【发布时间】:2016-05-28 23:23:08
【问题描述】:
我在线程中转发的电子邮件/电子邮件中的附件 ID 存在问题。
当从“源/原始”电子邮件(内联和普通附件)中获取附件时,我可以通过从 Office.context.mailbox.item.attachments 询问附件 ID 来成功地从 EWS 网络服务检索附件的内容
当我尝试从电子邮件的转发版本中获取相同的附件时,对于电子邮件中的每个附件,我都会收到“指定的附件 ID 无效。ErrorInvalidAttachmentId0”。如果我在发送之前转发电子邮件并在电子邮件中添加额外的附件,我会获得仅为“额外”附件而不是任何原始附件的附件内容。
该错误仅发生在 Outlook 桌面客户端。 (版本 16.0.6366.2062)。使用 chrome 或 Internet Explorer 时,OWA 中不存在此问题。
这是我的 API 用来调用 EWS 的代码。
string getAttachmentRequest =
@"<?xml version=""1.0"" encoding=""utf-8""?>
<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"">
<soap:Header>
<t:RequestServerVersion Version=""Exchange2013"" />
</soap:Header>
<soap:Body>
<GetAttachment xmlns=""http://schemas.microsoft.com/exchange/services/2006/messages""
xmlns:t=""http://schemas.microsoft.com/exchange/services/2006/types"">
<AttachmentShape/>
<AttachmentIds>
<t:AttachmentId Id=""{0}""/>
</AttachmentIds>
</GetAttachment>
</soap:Body>
</soap:Envelope>";
getAttachmentRequest = String.Format(getAttachmentRequest, attachmentId);
// Prepare a web request object.
HttpWebRequest webRequest = WebRequest.CreateHttp(ewsUrl);
webRequest.Headers.Add("Authorization", string.Format("Bearer {0}", authToken));
webRequest.PreAuthenticate = true;
webRequest.AllowAutoRedirect = false;
webRequest.Method = "POST";
webRequest.ContentType = "text/xml; charset=utf-8";
// Construct the SOAP message for the GetAttchment operation.
byte[] bodyBytes = System.Text.Encoding.UTF8.GetBytes(getAttachmentRequest);
webRequest.ContentLength = bodyBytes.Length;
Stream requestStream = webRequest.GetRequestStream();
requestStream.Write(bodyBytes, 0, bodyBytes.Length);
requestStream.Close();
// Make the request to the Exchange server and get the response.
HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
【问题讨论】:
-
您可以使用makeEwsRequestAsync 让他们获得客户端吗?还是从服务器发出 GetAttachments EWS 请求?
-
当插件在 Internet Explorer/Chrome 的 OWA 中运行时,我可以正确获取所有附件。当我在 Outlook 2016 中针对完全相同的电子邮件运行完全相同的插件时,它会以某种方式获取无效的附件 ID。实际上,我还没有保存浏览器生成的附件 ID,并将它们与 Outlook 中受限即生成的附件 ID 进行比较。但是话又说回来,不知道我会用这些信息做什么。 (将尝试使用客户端 makeEwsRequestAsync 函数,但我仍然想知道为什么这不起作用)
-
只记得我已经尝试过了。这不被允许。 “请注意,服务器端代码应通过直接创建 EWS 请求来访问 EWS。不能使用 Mailbox.makeEwsRequestAsync 方法访问 GetAttachment 操作。” msdn.microsoft.com/en-us/magazine/dn201750.aspx
标签: office365 outlook-addin exchangewebservices office365-apps