Download email body and include the inline attachments

WardH 61 Reputation points
2022-04-25T15:38:23.97+00:00

Hi
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

Thanks
Ward

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

2 answers

Sort by: Most helpful
  1. Srinivasa Rao Darna 6,686 Reputation points Microsoft Vendor
    2022-04-27T15:20:36.62+00:00

    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  
    	.Request()  
    	.GetAsync();  
    

    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  
    	.Request()  
    	.GetAsync();  
    

    References:
    Get MIME content
    attachment-get

    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
    2023-03-06T14:50:41.15+00:00

    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