Office365 Can';t在Outlook 2016桌面版的Outlook加载项中,从EWS获取转发电子邮件的附件

Office365 Can';t在Outlook 2016桌面版的Outlook加载项中,从EWS获取转发电子邮件的附件,office365,outlook-addin,exchangewebservices,office365-apps,Office365,Outlook Addin,Exchangewebservices,Office365 Apps,我在一个线程中转发的电子邮件/电子邮件中的附件id有问题 从“源/原始”电子邮件(内联和普通附件)获取附件时,我可以通过从Office.context.mailbox.item.attachments 当我尝试从转发版本的电子邮件中获取相同的附件时,我会为电子邮件中的每个附件获取“指定的附件Id无效。ErrorInvalidateTachmentID0”。如果我转发了一封电子邮件,并在发送之前向电子邮件添加了一个额外的附件,那么我只会获得“额外”附件的附件内容,而不会获得任何原始附件的内容 此错

我在一个线程中转发的电子邮件/电子邮件中的附件id有问题

从“源/原始”电子邮件(内联和普通附件)获取附件时,我可以通过从
Office.context.mailbox.item.attachments

当我尝试从转发版本的电子邮件中获取相同的附件时,我会为电子邮件中的每个附件获取“指定的附件Id无效。ErrorInvalidateTachmentID0”。如果我转发了一封电子邮件,并在发送之前向电子邮件添加了一个额外的附件,那么我只会获得“额外”附件的附件内容,而不会获得任何原始附件的内容

此错误仅在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();
string getAttachmentRequest=
@"
";
getAttachmentRequest=String.Format(getAttachmentRequest,attachmentId);
//准备web请求对象。
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”;
//为GetAttchment操作构造SOAP消息。
byte[]bodyBytes=System.Text.Encoding.UTF8.GetBytes(getAttachmentRequest);
webRequest.ContentLength=bodyBytes.Length;
Stream requestStream=webRequest.GetRequestStream();
写入(bodyBytes,0,bodyBytes.Length);
requestStream.Close();
//向Exchange服务器发出请求并获取响应。
HttpWebResponse webResponse=(HttpWebResponse)webRequest.GetResponse();

安德鲁·萨拉马托夫在yammer上回答了这个问题:


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

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

# 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\u PropertySet
参数会导致一个错误,修复程序只是将其删除,即:

$attached_email.load()

你能让他们在客户端使用吗?或者从服务器发出GetAttachments EWS请求?当加载项在Internet Explorer/Chrome的OWA中运行时,我可以正确获取所有附件。当我在Outlook 2016中针对完全相同的电子邮件运行完全相同的加载项时,它不知何故获得了无效的附件id。实际上,我还没有保存由浏览器生成的附件id,并将其与outlook中受限ie中生成的附件id进行比较。但话说回来,我不知道我会如何处理这些信息。(将尝试使用clientside makeEwsRequestAsync函数,但我仍然想知道为什么它不起作用)只是记得我已经尝试过了。这是不允许的。“请注意,服务器端代码应该通过直接创建EWS请求来访问EWS。您不能使用Mailbox.makeEws-RequestAsync方法来访问GetAttachment操作。”这有点没有帮助,因为这是我唯一可以找到此引用的位置,并且没有指向工作项/预期解决方案的链接,或者是一个更详细的解决方案,关于“撤退并拨打EWS电话”的含义。