Created
January 7, 2021 09:14
-
-
Save aspose-com-gists/2b4338c1d2915a7cd5cd01db14c965ba to your computer and use it in GitHub Desktop.
Convert Email to PDF in C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create and set load options | |
var loadOptions = new Aspose.Words.LoadOptions(); | |
loadOptions.LoadFormat = LoadFormat.Mhtml; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create an instance of PDFSaveOptions class | |
var pdfSaveOptions = new Aspose.Words.Saving.PdfSaveOptions(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create an instance of Document and load the MTHML from MemoryStream | |
var document = new Aspose.Words.Document(ms, loadOptions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load email message using file | |
MailMessage mailMsg = MailMessage.Load("message.msg"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Save email as PDF | |
document.Save("email-to-pdf.pdf", pdfSaveOptions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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