I have a problem with attachment id's of attachments in forwarded emails/emails in a thread.
When fetching attachments from the "source/original" email (both inline and normal attachments) I can successfully retrieve the content of the attachment from the EWS webservice by asking for attachment id's from Office.context.mailbox.item.attachments
When I try to get the same attachments from a fowarded version of the email I get "The specified attachment Id is invalid.ErrorInvalidAttachmentId0" for every attachment in the email. If I forward an email and add an extra attachment to the email before sending I get get the content of the attachment just for the "extra" attachment, not for any of the original attachments.
The error only occurs with the Outlook desktop client. (version 16.0.6366.2062). The problem does not exist in OWA when using chrome or internet explorer.
This is the code my API uses to call 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();