For sharing and referencing the email content, you may need to convert your email message to PDF format. In this article, you will learn the conversion of email message files like EML and MSG into PDF using C#. In one of the other blog posts, we have already discussed the conversion of emails to PDF using Java. This will help to automate the email conversions within your desktop or web-based applications.
The following topics are covered below:
.NET API for Email Conversion
GroupDocs.Conversion for .NET is the API that allows the conversion of email messages to other formats. In this article, we will use that API for converting MSG and EML messages to PDF format using C#. Furthermore, the API allows the back and forth conversion of word-processing documents, spreadsheets, presentations, eBooks, images, and many other file formats within your .NET applications.
PM> Install-Package GroupDocs.Conversion
Convert MSG to PDF in C#
The following are the steps to convert the Outlook MSG files to PDF format.
- Load the MSG file using the Converter class.
- Create PDF conversion options using PdfConvertOptions class.
- Call the Convert method to convert the MSG file to PDF format.
The following source code converts the MSG file to PDF using C#.
Below shown is the Microsoft Outlook MSG file. Furthermore, the PDF file is also shown here which is obtained after conversion from the MSG file using the above code.
Convert EML to PDF using C#
If you want to convert your email messages stored in EML format into PDF format, it can be efficiently done using similar lines of code. The following are the steps to convert EML files to PDF.
- Load the EML message file using the Converter class.
- Using PdfConvertOptions class, create conversion options for the PDF file.
- Call the Convert method to convert the EML files to PDF format. Pass the path of the resultant PDF file and the conversion options as parameters.
Below are the EML file and the converted PDF file screenshots, that have been converted using the above code.
Further, you can change the appearance of the output PDF files as needed. You can visit documentation for such purposes and for many more features.
Get a Free API License
You can get a free temporary license in order to use the API without the evaluation limitations.
To conclude, we learned how to convert the EML and MSG files to PDF using the .NET Conversion API. Additionally, we can programmatically apply customization on PDF files to get the outcome in the desired style.