This tutorial briefly describes the step-by-step procedure to convert Outlook Email to HTML in C#. This guide provides instructions for configuring the environment and how to develop the C# EML to HTML converter application using the steps explained in this post. Here are the main points along with a sample code snippet to convert Outlook Email to HTML using C#.
Steps to Convert Outlook Email to HTML in C#
- Install GroupDocs.Conversion for .NET package from the NuGet package manager in the .NET application to convert Outlook Email to HTML
- Add a reference to the GroupDocs.Conversion namespace for developing the Outlook Email to HTML conversion functionality
- Initialize the Converter class for loading the input EML or MSG file from the disk
- Instantiate the MarkupConvertOptions class for setting up the parameters for customizing the HTML document
- Finally, call the Convert method to save Outlook Email as HTML on the disk
The convert MSG to HTML C# application development is an easy process by consuming the above stepwise instructions in a sequence. To convert the EML file to HTML format, the Converter class object allows loading the input email file from the disk after configuring the package and including a reference to the essential namespaces. The MarkupConvertOptions enables you to define various properties for customizing the converted HTML file and then the Convert method stores the resultant file on the disk after performing the conversion to the specified format.
Code to Convert Outlook Email to HTML in C#
using System; | |
using GroupDocs.Conversion.Options.Convert; | |
namespace ConvertOutlookEmailToHtmmlInCSharp | |
{ | |
class Program | |
{ | |
public static void Main(string[] args) // Main function to convert outlook email to HTML using C# | |
{ | |
// Remove the watermark in output HTML document by adding license | |
string licensePath = "GroupDocs.Conversion.lic"; | |
GroupDocs.Conversion.License lic = new GroupDocs.Conversion.License(); | |
lic.SetLicense(licensePath); | |
// Load the source EML file for conversion to HTML | |
var converter = new GroupDocs.Conversion.Converter("sample.eml"); | |
// Set the conversion options for HTML document to customize the output file | |
MarkupConvertOptions options = new MarkupConvertOptions(); | |
// Convert and save the EML in HTML format | |
converter.Convert("converted.html", options); | |
Console.WriteLine("Done"); | |
} | |
} | |
} |
The above example demonstrates how to write the code to convert Outlook Email to HTML code using C# for performing the document transformation. This sample code takes an Outlook email file as input and then converts it into an HTML format and saves it on the specified path on the disk. However, you may alter this working example by consuming the MarkupConvertOptions object for defining a variety of parameters to customize the resultant HTML file as per your requirements.
We have discussed the document conversion process to export Outlook Email to HTML using C# and developed an example for it. Recently, we published an article to change MPP to PDF using C#, have a look at how to convert MPP to PDF in C# guide for more information.