Convert EML or MSG file to PDF in C#

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.

Convert Email Messages to PDF in C#

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.

You can download the DLLs or MSI installer from the downloads section or install the API in your .NET application via NuGet.

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.

  1. Load the MSG file using the Converter class.
  2. Create PDF conversion options using PdfConvertOptions class.
  3. 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.

MSG file to be converted to PDF
MSG file
Converted PDF file from MSG
PDF file converted from MSG format using the above C# 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.

  1. Load the EML message file using the Converter class.
  2. Using PdfConvertOptions class, create conversion options for the PDF file.
  3. 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.

EML file to be converted to PDF
EML file
Converted PDF file from EML
PDF file converted from EML format using C#.

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.

Conclusion

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.

You may learn more about GroupDocs.Conversion for .NET using documentation. Many more examples are available at GitHub. For queries, contact us via the forum.

See Also