How to Convert Outlook Email to PDF using C#

In this easy tutorial, we will learn how to convert Outlook Email to PDF using C# along with detailed steps to configure the environment. You will see that in order to convert MSG to PDF C# based API can be used and you can use this example in any of the commonly available operating systems like Windows, macOS, or Linux.

Steps to Convert Outlook Email to PDF using C#

  1. Install Aspose.Email and Aspose.Words libraries from NuGet package manager tool in Visual Studio
  2. Initialize the MailMessage class object to load the MSG or EML format email file
  3. Save the loaded Email (MSG/EML) file as a stream to an intermediate MHTML format
  4. Set the LoadFormat to MHTML and initialize the Document class object to load the MHTML created in the previous step
  5. By using the Save method in C# EML to PDF conversion is done

By using the above steps in C# MSG to PDF conversion application is developed. We will load the MSG or EML file using the MailMessage class object in the first step. Then we will save the loaded email file to a stream in an intermediate MHTML format. In the subsequent steps, we will load the intermediate MHTML using the Document class object. Finally to convert EML to PDF C# Save method will be used and PDF will be saved on the disk.

Code to Convert Outlook Email to PDF using C#

In the above example, in order to convert EML to PDF C# is used with the help of simple API calls and well defined steps. The above example can be used for Email files in MSG and EML formats. You can customize the output PDF by setting properties like ColorMode, Compliance, ImageCompression and JpegQuality.

To convert MSG to PDF C# based API is explored in this article. If you are looking for how to send Email in C#, refer to the article on how to send Email in C#.

 English