Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Created January 7, 2021 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/2b4338c1d2915a7cd5cd01db14c965ba to your computer and use it in GitHub Desktop.
Save aspose-com-gists/2b4338c1d2915a7cd5cd01db14c965ba to your computer and use it in GitHub Desktop.
Convert Email to PDF in C#
// Load email message
MailMessage mailMsg = MailMessage.Load("message.msg");
MemoryStream ms = new MemoryStream();
mailMsg.Save(ms, Aspose.Email.SaveOptions.DefaultMhtml);
// create an instance of LoadOptions and set the LoadFormat to Mhtml
var loadOptions = new Aspose.Words.LoadOptions();
loadOptions.LoadFormat = LoadFormat.Mhtml;
// create an instance of Document and load the MTHML from MemoryStream
var document = new Aspose.Words.Document(ms, loadOptions);
// create an instance of HtmlSaveOptions
var saveOptions = new Aspose.Words.Saving.PdfSaveOptions();
document.Save("email-to-pdf.pdf", saveOptions);
// Create and set load options
var loadOptions = new Aspose.Words.LoadOptions();
loadOptions.LoadFormat = LoadFormat.Mhtml;
// create an instance of PDFSaveOptions class
var pdfSaveOptions = new Aspose.Words.Saving.PdfSaveOptions();
// Create an instance of Document and load the MTHML from MemoryStream
var document = new Aspose.Words.Document(ms, loadOptions);
// Load email message using file
MailMessage mailMsg = MailMessage.Load("message.msg");
// Save email as PDF
document.Save("email-to-pdf.pdf", pdfSaveOptions);
// Create memory stream
MemoryStream ms = new MemoryStream();
// Save email message into memory stream
MailMessage.Save(ms, Aspose.Email.SaveOptions.DefaultMhtml);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment