I am trying to save an email that I have retrieved via the EWS managed Api but get the following message when I try and open the file.
"Cannot open file c:\bla\bin... The file may not exist, you may not have permission to open it, or it may be open in another program. Right-click the folder that contails the file, and then click Properties to check your permissions for the folder. "
Any help will be much appriciated.
See code below:
public static void save_entire_email_to_disk()
ExchangeService service = GetService();
var findResults = service.FindItems(WellKnownFolderName.Inbox, new ItemView(10));
foreach (var result in findResults)
if (result is EmailMessage)
var message = result as EmailMessage;
MimeContent mc = message.MimeContent;
FileStream oFileStream = new FileStream("Test.msg", FileMode.Create);
oFileStream.Write(mc.Content, 0, mc.Content.Length);
- Edited by Zi Makki Monday, September 07, 2009 2:45 PM Code looked BAD :(
If I change the extension that it saves to (.msg -> .eml). I am able to get into the eml and view the mail and the contents but unfortunately I need the file to be a msg not and eml.
Why do I get that message when I try and open the msg??? Am I missing a trick?
Any pointers will be brilliant!
What you are doing is saving the MIME content (or the RFC 822 formatted message) to a file this is not the same as compound msg format which basically contains all the MAPI properties of the message. There is no easy way to save a message to MSG format with EWS and you may want to read http://blogs.msdn.com/stephen_griffin/archive/2008/01/08/no-msg-for-you.aspx to see if this has relevance to you. Other then that you may want to look at using MAPI see http://support.microsoft.com/kb/171907/en-us.
- Proposed as answer by Deva [MSFT]Microsoft employee Thursday, July 07, 2011 2:23 AM
Definitely it is possible to save as .msg file. Found this code: