Stavros
Stavros

Reputation: 6110

Save email WITH attachments using EWS Managed API 2.0

I'm using Exchange Web Services Managed API 2.0 to connect to Exchange server 2010 and then find out new emails received. Now I want to save a copy of the email to a file on the disk.

So, I do have an

Exchange.WebServices.Data.EmailMessage email    

that is ready to be saved. Now, what?
The following code will save it, but without the attachments..

FileStream fs = new FileStream(filepath, FileMode.Create);
fs.Write(email.MimeContent.Content, 0, email.MimeContent.Content.Length);
fs.Close();

I do not want to use any paid third party to integrate. Any help will be appreciated.

p.s. I know this question has been asked before, but it was either never answered or targeting an old API.

Upvotes: 2

Views: 1815

Answers (1)

Stavros
Stavros

Reputation: 6110

To my surprise, the email (saved as .eml) actually contains the attachments!!

The problem was that I was opening this from IE (through a link to the filesystem), that was trying to work as Email Viewer, but wasn't showing the attachments!

If you save the email (.eml) on the disk (in my case, force download) and open it with Outlook 2010, it will be with attachments and everything!!

Upvotes: 1

Related Questions