outlookoffice-jsoutlook-addinoffice-addinsjavascript-api-for-office

Relate Outlook message inline attachment to element in HTML body


When using Office.js to retrieve the body of an email that has inline attachments, we receive HTML like this:

<div>
<div dir="ltr">
<div style="color:black;font-size:12pt;font-family:Calibri,Arial,Helvetica,sans-serif;background-color:white;">
This email has images in the body.</div>
<div style="color:black;font-size:12pt;font-family:Calibri,Arial,Helvetica,sans-serif;background-color:white;">
<img data-imagetype="AttachmentByCid" originalSrc="cid:ab24f213-f1a6-4804-ad70-25a4d3ac5f86" naturalHeight="0" naturalWidth="0" src="cid:ab24f213-f1a6-4804-ad70-25a4d3ac5f86" data-outlook-trace="F:1|T:1" tabindex="-1" size="9026" style="max-width:100%;">
<img data-imagetype="AttachmentByCid" originalSrc="cid:be90d9aa-49a6-48fb-b4b9-d50950aefae3" naturalHeight="0" naturalWidth="0" src="cid:be90d9aa-49a6-48fb-b4b9-d50950aefae3" data-outlook-trace="F:1|T:1" tabindex="-1" size="60886" style="max-width:100%;">
<br>

</div>
</div>
</div>

Where the <img> tags are where the inline image attachments would be.

The attachments property on the mailbox item lists attachment metadata like this:

{
attachmentType: "file",
contentType: "image/jpeg",
id: "AAMkADFlM2Q0MzdkLTJhZWQtNGQzNS05YWI2LWMwYmNkZmMwODNmZgBGAAAAAAAbEbu84Nj1SIfOZGQpQsg/BwC74mYLmMGJSYnZmTQHpD7TAAAAAAEJAAC74mYLmMGJSYnZmTQHpD7TAAE1znR7AAABEgAQACz3QOlxzApEvhIoK7iHWoc=",
isInline: true,
name: "home_team.jpg",
size: 9341
}

I can't any link between the first image tag and this attachment object. Is there some other way of identifying where each inline attachment is in the message?


Solution

  • The Office.AttachmentDetails interface doesn't provide any property for the content ID value. You need to use EWS to get a property value. See Call web services from an Outlook add-in to get started quickly. The Attachment.ContentId property gets or sets the content identifier of the attachment. ContentId can be used as a custom way to identify an attachment in order to reference it from within the body of the item that the attachment belongs to.