Get email attachments via Graph api, missing ContentBytes

André Pereira 21 Reputation points

I have a project where I am retrieving emails via graph api, but I also need to get the attachments from the email.
I can see all of them, but I can't see the property contentbytes so I can save them on the local hard drive.
var attach = await graphClient.Users[UserEmail].Messages[Email.Id].Attachments[EmailAttachment.Id].Request().GetAsync();
If I look at here, looks like the property should be returned but it is not present on the nuget package for c#
How do I get the attachments so I can save them to my hard drive?

Microsoft Graph Mail API
Microsoft Graph Mail API
A Microsoft API that supports accessing data in users' primary mailboxes and in shared mailboxes.
798 questions
0 comments No comments
{count} votes

Accepted answer
  1. Srinivasa Rao Darna 6,461 Reputation points

    Hi @André Pereira ,

    Based on your request, to get mail message attachment content you can use GET /me/messages/{id}/attachments/{id}/$value, sample C# snippet.

    var stream = await graphClient.Me.Messages["{id}"].Attachments["{id}"].Content  

    Refer Example 6: Get the raw contents of a file attachment on a message

    Hope this helps.
    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful