There could be various scenarios when you need to embed the content of the emails within your web or desktop applications. In such cases, you can convert the email messages into a format that can easily be embedded and displayed. One of the possible solutions is email to PDF conversion. This article provides a step-by-step guide and code sample of how to convert an email to PDF in C#. You can follow the the provided steps and use the code sample for EML to PDF and MSG to PDF conversion in C#.
- C# Email to PDF Converter - Free Download
- Steps to Convert Emails to PDF in C#
- C# Email to PDF Conversion - Complete Code
- Get Free License
C# Email to PDF Converter - Free Download
Aspose.Email for .NET is a C# class library that is designed to create and manipulate popular email formats from within the .NET applications. In combination with Aspose.Words for .NET, the API lets you convert the EML and MSG email messages to PDF format with high fidelity. You can either download the APIs’ DLLs or install them within your .NET applications using NuGet.
PM> Install-Package Aspose.Words
PM> Install-Package Aspose.Email
Steps to Convert EML or MSG to PDF in C#
The following are the steps to convert email messages to PDF format in C#.
- Load the email file using MailMessage class.
- Save the email message into a MemoryStream object as default MHTML format.
- Create an instance of Aspose.Words.LoadOptions class and set the load format as MHTML.
- Instantiate Aspose.Words.Document class and pass MemoryStream and LoadOptions objects as parameters to its constructor.
- Create an instance of Aspose.Words.Saving.PdfSaveOptions class.
- Convert the email to PDF using Document.Save(“email-to-pdf.pdf”, PdfSaveOptions) method.
Email to PDF C# Conversion - Complete Code
The following is the complete code to convert an email message to PDF using Aspose.Emails for .NET and Aspose.Words for .NET APIs.
EML or MSG to PDF C# Converter - Get a Free License
You can get a free temporary license in order to convert emails to PDF without evaluation limitations.
Aspose Email to PDF Converter - Live Demo
Conclusion
Email to PDF conversion may come into practice when you need to embed the email messages within your web or desktop applications. Therefore, in this article, you have learned how to convert emails to PDF in C# within your .NET applications. In order to explore more about the APIs being used, you can visit the following documentations.