graph api - mismatch between cid attachment names in email message body, and the names of attachments return via API call

Alex S 1 Reputation point
2022-10-09T19:53:15.207+00:00

I use curl to

  1. list email messages (and their body, of course)
  2. read their attachments without value- i.e.. https://graph.microsoft.com/v1.0/users/{UserId}/messages/{MessageId}/attachments?$select=name,id,contentType,isInline,
  3. read attachment raw content e.g. https://graph.microsoft.com/v1.0/users/{UserId}/messages/{MessageId}/attachments/{AttachmentId}/$value

Some messages have inline attachments (CID attachment references) in the body, and I am trying to replace these references with Base64 of #3, based on the match between the CID name and the name I am getting from #2.

Example :

1 message body contains: <img src="cid:image001.png@01D8D9DB.51722550" .

2 API call contains {..."isInline" : true, "name" : "image001.png",...} . Here there is a match in names, and I can preform the replacement using the value from #3.

However sometimes the attachment names from #2 do not match the CID attachment names from the body
For example, the attachment names from API call #2 are
image001, image002...
while the CID references are
<img src="cid:183b27ac45e855d34"...,
<img src="cid:183b27ac45fbda4f17" alt="cid:image007.png@01D869CB.F672DCF0" ...

How to find how to match these names?

Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. HarmeetSingh7172 4,826 Reputation points
    2022-10-21T11:29:21.01+00:00

    Hello @Alex S

    Thanks for reaching out!

    Based on my understanding, you can use GET https://graph.microsoft.com/v1.0/users/{UserId}/messages?$expand=attachments endpoint to list the attachment details of all the emails, whether an attachment is in message body or in as an attachment.

    To get attachments of specific message, you can use GET https://graph.microsoft.com/v1.0/users/{UserId}/messages/{MessageID}?$expand=attachments endpoint.

    The API response will have all the details of attachments for a specific message.

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote. If you have any further questions about this answer, please click Comment.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.