Download email body and include the inline attachments

WardH 61 Reputation points

I am trying to write a C# app to download the message body in html and to include the inline attachment. Can I get ideally some c# to do that.

Failing that the method to handle it (steps) technique


Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,353 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Srinivasa Rao Darna 6,711 Reputation points Microsoft Vendor

    Hi @WardH ,

    Take a look at this get-message-content, you can get the entire mail response including attachments.
    The response is returned MIME, that body in plain text, body in html and also attachments with Base64 encoding.

    GraphServiceClient graphClient = new GraphServiceClient( authProvider );  
    var stream = await graphClient.Me.Messages["{message-id}"].Content  

    To get attachments of message, use below snippet.

    GraphServiceClient graphClient = new GraphServiceClient( authProvider );  
    var stream = await graphClient.Me.Messages["{message-id}"].Attachments["{attachment-id}"].Content  

    Get MIME content

    Hope this helps.

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

    1 person found this answer helpful.

  2. Henrik Flyger Holm 0 Reputation points

    Im currently trying to download the data of an inlined image however the Attachments property of the email does not contain any elements. Its empty. If I look at the body of the message it does indeed have an < img > property but Attachments is empty.

    How to I get to the data of the inlined attachment?

    0 comments No comments