Save the MailItem object as a .msg file

Following the code below

How to save an object MailItemas a file .msg?

Or another way to put this: How can I create a file .msgusing the attributes (sender, cube, heap, piece, object, body, etc.) of the object MailItem?

+5
source share
2 answers
mailItem.SaveAs(savepath);

Where mailItem is Outlook MailItem, and the save path, for example:

String savepath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\" + filename + ".msg";

If you want to use the MailItem theme as the file name, you can remove the invalid characters for the file names:

String filename = mailItem.Subject;
string invalid = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars());

foreach (char c in invalid)
{
    filename = filename.Replace(c.ToString(), "");
}
+5
source

All Articles