Platinum Fire
Platinum Fire

Reputation: 512

Convert MailItem to MSG in memory rather than filesystem

At the moment I am base64 encoding a mailItem by writing the mailItem to an MSG file with this:

 mailItem.SaveAs(@"c:\path\to\save\mail.msg", Outlook.OlSaveAsType.olMSG);
 FileStream fs = new FileStream( fullPath, FileMode.Open, FileAccess.Read );
 byte[] filebytes = new byte[fs.Length];
 fs.Read( filebytes, 0, Convert.ToInt32( fs.Length ) );
 string encodedData = Convert.ToBase64String( filebytes, 
 Base64FormattingOptions.InsertLineBreaks );

I've looked long and hard and not found a way to do this without writing the MSG to the hard drive.

Is there a way I can do this where I don't need to write to the hard drive?

Thanks!

Upvotes: 2

Views: 1139

Answers (2)

Dmitry Streblechenko
Dmitry Streblechenko

Reputation: 66306

No, not using OOM. It would be possible in Extended MAPI (C++ or Delphi).

Upvotes: 1

germoo
germoo

Reputation: 26

Per Justin Cooney (emphasis his):

The Outlook.MailItem object is in fact a COM object that cannot be dynamically saved/loaded. To achieve the desired save/load functionality the Outlook.MailItem object will first need to be converted to a .MSG file.

This is something that I would like to do as well, but alas cannot due to the limitations above. I am currently writing the file to a temp location, passing the path, converting to a Base64 string and deleting the file once successful.

Upvotes: 1

Related Questions