Export Email

VSTO

Below is the code to export email using VSTO Outlook.


  string FilePath = @"E:\Aspose\Aspose VS VSTO\Sample Files\ExportEmail.msg";

 // Create Application class and get namespace

 Outlook.Application outlook = new Outlook.Application();

 Outlook.NameSpace ns = outlook.GetNamespace("Mapi");

 object _missing = Type.Missing;

 ns.Logon(_missing, _missing, false, true);

 // Get Inbox information in objec of type MAPIFolder

 Outlook.MAPIFolder inbox = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);

 Outlook.MailItem item = inbox.Items[0];

 item.SaveAs(FilePath,_missing);       

Aspose.Email

Below is the code to export email using aspose.email for .NET.


  string FilePath = @"E:\Aspose\Aspose VS VSTO\Sample Files\ExportEmail.msg";

 //Create an instance of the MailMessage class

 MailMessage msg = new MailMessage();

 //Export to MHT format

 msg.Save(FilePath, SaveOptions.DefaultMsg);

Download Source Code

Download Running Example