Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aspose-com-kb/15c9b492e8255901ad7ae3dc8e90e7e4 to your computer and use it in GitHub Desktop.
Save aspose-com-kb/15c9b492e8255901ad7ae3dc8e90e7e4 to your computer and use it in GitHub Desktop.
How to Convert Outlook Email to Words using C#. For more details: https://kb.aspose.com/email/net/how-to-convert-outlook-email-to-word-using-csharp/
using System.IO;
using Aspose.Email;
using Aspose.Words;
namespace KBEmail
{
public class EmlToWord
{
public static void ConvertEmailTWord()
{
string FilePath = @"C:/TestData/";
// Applying product license to read the MSG file
Aspose.Email.License emailLicense = new Aspose.Email.License();
emailLicense.SetLicense(FilePath + "Conholdate.Total.Product.Family.lic");
// Applying the product license to convert MHTML to DOCX
Aspose.Words.License wordsLicence = new Aspose.Words.License();
wordsLicence.SetLicense(FilePath + "Conholdate.Total.Product.Family.lic");
using (MemoryStream mhtmlStream = new MemoryStream())
{
// Open the MSG or EML file from the disk
MailMessage srcMessage = MailMessage.Load(FilePath + "Message.msg");
// Save email to MHTML
srcMessage.Save(mhtmlStream, Aspose.Email.SaveOptions.DefaultMhtml);
// Reset the Memory stream position
mhtmlStream.Position = 0;
// Initialize the LoadOptions to set the LoadFormat to Mhtml
Aspose.Words.Loading.LoadOptions loadOptions = new Aspose.Words.Loading.LoadOptions();
loadOptions.LoadFormat = LoadFormat.Mhtml;
// Create the Document class object to load the MTHML from MemoryStream
Aspose.Words.Document mhtmlDocument = new Aspose.Words.Document(mhtmlStream, loadOptions);
// Save the MHTML to DOCX using C#
mhtmlDocument.Save(FilePath + "SaveEmailAsDoc.docx");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment