6

I'm using Microsoft Graph to pull email data from a mailbox. When I get the content, I find embedded images with content like so:

<img id="_x0000_i1029" 
     width="1366" 
     height="672" 
     data-outlook-trace="F:1|T:1" 
     src="cid:image005.png@01D4DE3D.90A3C410" 
     style="width:14.2291in; height:7.0in">

When the property hasAttachments is true, I look for images that match and replace the content and it works great. The problem is I see embedded image tags like this on messages where hasAttachments is false.

Where can I get the image data Graph says the Message has no attachments but there clearly are embedded images?

Note that the image renders in Outlook for the Web with a tag like:

<img data-imagetype="AttachmentByCid"        
     originalsrc="cid:image005.png@01D4DE3D.90A3C410" 
     data-custom="AAMkADY1YjgxM2Y4LTE5NTUtNDBjMy1iZDY0LWIzN..." 
     naturalheight="672" 
     naturalwidth="1366" 
     src="https://attachments.office.net/owa/mailboc@mydomain.onmicrosoft.com/service.svc/s/GetAttachmentThumbnail?id=AAMkADY1YjgxM2Y4LTE5NTUtNDBjMy1iZDY0LWIzN...&amp;thumbnailType=2&amp;owa=outlook.office365.com&amp;scriptVer=2019031102.10&amp;X-OWA-CANARY=kKWSUkiFW0WjlPXXXXXXXXX.&amp;token=eyJhbGciOiJSU...&amp;animation=true" 
     id="_x0000_i1029" 
     data-outlook-trace="F:1|T:1" 
     style="width: 1024.49pt; height: 504pt; cursor: pointer;" 
     crossorigin="use-credentials" >
Marc LaFleur
  • 31,987
  • 4
  • 37
  • 63
Cleanshooter
  • 2,314
  • 4
  • 19
  • 29

1 Answers1

7

Using Microsoft Graph API you can get all attachments of a mail:

GET https://graph.microsoft.com/v1.0/me/messages/{id}/attachments

or

GET https://graph.microsoft.com/v1.0/users/{id | userPrincipalName}/messages/{id}/attachments

When you get all attachments you can check property isInline to find embedded images.

You can get attachments even if an email has property hasAttachments set to false, because that property is related to not inline attachments.

RiccardoGDev
  • 245
  • 1
  • 7
  • wouldn't have though to just try getting attachments from a message that said it didn't have any but low an behold there they are! Thanks for the answer. – Cleanshooter Mar 29 '19 at 15:38
  • 1
    @RiccardoGDev thanks for great reply, but in this case, I need to check attachments for all email by he API, because `hasAttachments` always false for inline, Is ther any way to identify this via GET /message/{id} call? – HarisH Sharma Dec 12 '19 at 06:15
  • I spent HOURS banging my head against a wall. THANK YOU for this – Kaptein Babbalas Jul 06 '22 at 08:42