92
Views
4
Comments
Solved
How to get email attachment as a file from email with MS Graph API
Question

Hello,

In one of our project requirement is to read email and fetch attachments if any. We achieved this functionality via MS Graph API where we are getting all attachment in file format except email. 

Please refer attached file for the response where attachment is type of email and response is in chunk and not in single file content. 

Struggling to get email as a file, any pointer would help

Thanks

Prajakta Roshankhede

Response 2 with expand new.txt
2022-04-19 13-20-22
Andrea Lembo
Solution

Hi,

If you need to retrieve the email as file ( as .eml) you can use the endpoint

/users/{id}/messages/{id}/$value 

This is the same for attachments:

/users/{id}/outlook/tasks/{id}/attachments/{id}/$value 

This is the official documentation links: get-mime-message

Br,

AL

2021-01-12 14-29-49
Prajakta Roshankhede

Hello @Andrea Lembo,

I did try the same solution and was about to post the same. 

addition step is to store response in .eml file.

Thanks for your input.

Regards
Prajakta Roshankhede

2022-08-03 04-32-50
Ravi Punjwani

Hi Prajakta,

I can easily see two important JSON properties that talk aboutL:

  • Email preview
  • Email body

of your email.


Also I noticed the property

    "hasAttachments":false


This email doesn't have any attachment. Hence you're unable to see any of them.


Hence, the email body and preview is available. Attachments are not sent in this email, which is why it has false value in hasAttachments.


Let me know if I misunderstood something in your question.

2021-01-12 14-29-49
Prajakta Roshankhede

Hello Ravi,

This response itself attachment of email (Read Email -> Fetch Attachment ->  Attachment Response(attached sample))
If attachment is type of word doc then response would be refer attached response file

Word doc response.txt
2022-04-19 13-20-22
Andrea Lembo
Solution

Hi,

If you need to retrieve the email as file ( as .eml) you can use the endpoint

/users/{id}/messages/{id}/$value 

This is the same for attachments:

/users/{id}/outlook/tasks/{id}/attachments/{id}/$value 

This is the official documentation links: get-mime-message

Br,

AL

2021-01-12 14-29-49
Prajakta Roshankhede

Hello @Andrea Lembo,

I did try the same solution and was about to post the same. 

addition step is to store response in .eml file.

Thanks for your input.

Regards
Prajakta Roshankhede

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.