Get email attachments via Graph api, missing ContentBytes

André Pereira 21 Reputation points
2022-11-08T16:05:18.13+00:00

Hi,
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, https://learn.microsoft.com/en-us/graph/api/attachment-get?view=graph-rest-1.0&tabs=http 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?
Regards

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

Accepted answer
  1. Srinivasa Rao Darna 6,686 Reputation points Microsoft Vendor
    2022-11-08T17:00:47.397+00:00

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

    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