【问题标题】:Can't get attachments from EWS for fowarded emails in an Outlook addin in the desktop version of Outlook 2016在 Outlook 2016 桌面版的 Outlook 插件中,无法从 EWS 获取转发电子邮件的附件
【发布时间】: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


【解决方案1】:

Andrew Salamatov 在 yammer 上回答了这个问题:

“这是我们在 Outlook 中的一个错误,我们在这种特定情况下计算 id 的方式。解决方法是进行 EWS GetItem 调用并以这种方式获取附件 id。所以如果你从 item 获得的 id .attachments[i].id 不起作用,您可以回退并进行 EWS 调用”

【讨论】:

  • 这有点无益,因为这是我唯一能找到引用的地方,并且没有指向工作项/预期解决方案的链接,或者关于“后备和拨打 EWS 电话”。
【解决方案2】:

当我们的 EWS 服务器升级到 2016 年时,我遇到了同样的问题,我之前在 PowerShell 中使用 EWS Managed API 通过以下方式下载附件电子邮件:

# load the email items.
$fiItems = $exchService.FindItems( $Inbox.Id, $email_filter, $ivItemView)  

# create the Attachment properties object
$attachment_PropertySet = new-object Microsoft.Exchange.WebServices.Data.PropertySet(
        [Microsoft.Exchange.WebServices.Data.ItemSchema]::Attachments)  

# LOAD THE ATTACHMENT AS AN EWS ITEM
$attached_email = $email_from_server.attachments[0]
$attached_email.load($attachment_PropertySet)

显然,对于新的 EWS 服务器,$attachment_PropertySet 参数会导致错误,修复方法只是将其删除,即:

$attached_email.load()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-15
    相关资源
    最近更新 更多