Convert MSG and EML Emails to HTML using C++

Convert Email to HTML using C++

In this day and age, emails are among the most common means of communication over the internet. As software developers, you see a wide variety of user requirements and usage scenarios. One such requirement might be that you want to embed the email content in web pages. For such cases, you would need to convert the emails into HTML format. In this article, you will learn how to convert MSG and EML emails to HTML or MHTML format programmatically using C++.

C++ API for Converting Emails to HTML

Aspose.Email for C++ is a native C++ library for creating, manipulating, and sending emails without requiring Microsoft Outlook to be installed. The API also provides the ability to convert emails to different formats, including HTML. You can either install the API through NuGet or download it directly from the Downloads section.

PM> Install-Package Aspose.Email.Cpp

Convert Email to HTML using C++

Converting email files to HTML is a breeze with Aspose.Email for C++ API. In just two lines of code, you can convert an email file to HTML format. The following are the steps to convert an email file to HTML format using C++.

The following is the sample code to convert email files to HTML format.

Converting Email to MHTML using C++

Similar to converting an email to HTML, you can convert an email file to MHTML format by passing Aspose::Email::SaveOptions::get_DefaultMhtml() as the second parameter of the MailMessage->Save (System::String fileName, System::SharedPtr<SaveOptions> options) method. The following are the steps to convert an email file to MHTML format.

The following is the sample code to convert email files to MHTML format.

Export Email to HTML with Header

By default, the generated HTML does not include the email header information. To export the header information, you can use the HtmlSaveOptions class. The following are the steps to convert email files to HTML format with the header information included in the resulting HTML.

The following is the sample code to convert emails to HTML with header information.

Email to HTML Conversion with custom Timezone

Aspose.Email for C++ provides you the ability to convert emails by specifying a custom timezone. The resulting HTML file will show the time in the selected timezone. The following are the steps to convert email files to HTML format with a custom timezone.

The following is the sample code to convert email files to HTML format with a custom timezone using C++.

Get a Free License

You can try the API without evaluation limitations by requesting a free temporary license.

Live Demo

Conclusion

In this article, you have learned how to convert MSG and EML files to HTML and MHTML format using C++. You have also seen how to include header information in the generated HTML output. Furthermore, you have learned how to customize the timezone of the email. Aspose.Email for C++ provides many more features for working with email files. You can explore the API in detail by visiting the official documentation. If you have any questions, please feel free to reach us on our free support forum.

See Also