Exchange Web Service Managed Api - Save an email as an msg to disk
-
Monday, September 07, 2009 2:42 PMHi,
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;
message.Load(new PropertySet(ItemSchema.MimeContent));
MimeContent mc = message.MimeContent;
FileStream oFileStream = new FileStream("Test.msg", FileMode.Create);
oFileStream.Write(mc.Content, 0, mc.Content.Length);
oFileStream.Close();
}
}
}
Cheers,
Zi- Edited by Zi Makki Monday, September 07, 2009 2:45 PM Code looked BAD :(
All Replies
-
Monday, September 07, 2009 3:10 PM
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!
Zi
-
Tuesday, September 08, 2009 11:15 PM
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.
Cheers
Glen- Proposed As Answer by Deva [MSFT]Microsoft Employee Thursday, July 07, 2011 2:23 AM
-
Tuesday, October 26, 2010 12:08 AM
use Mail Processor API to convert EML to MSG to EML
see the link http://dci-software.com/MailProcessor/mpmain.html
-
Wednesday, January 19, 2011 9:48 AM
Definitely it is possible to save as .msg file. Found this code:
http://www.independentsoft.de/exchangewebservices/tutorial/downloadmessagetomsgfile.html

