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 EML or MSG email to PDF using C#.
- C# Email to PDF Conversion API
- Steps to Convert Emails to PDF using C#
- C# Email to PDF Conversion – Complete Code
- Get Free License
C# EML and MSG Emails to PDF Converter API
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 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 using 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.
C# Email to PDF 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.
Get a Free License
You can get a free temporary license in order to try the APIs without evaluation limitations.
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 email messages to PDF using C# within your .NET applications. In order to explore more about the APIs being used, you can visit the following documentations.