Emails are the primary source of communication over the internet, especially in business environments. There might be cases such as discussing and finalizing the client’s software requirements for product development. After completing the software requirements, you might need to generate a final set of documents containing the emails and other details to share with your team. In such scenarios, converting the email to PDF may prove to be helpful. In this article, you will learn how to convert an email message to PDF format using C++.
C++ Email to PDF Conversion API
To convert email to PDF, we will use Aspose.Email for C++ and Aspose.Words for C++ APIs. The former is a native C++ library for creating, manipulating, and converting Outlook files. Whereas, the latter allows you to generate, modify and convert Microsoft Word files. Furthermore, it also supports converting files to PDF format. We will use Aspose.Email for C++ for loading email files and Aspose.Words for C++ for their conversion to PDF format. You can either install the API through NuGet or download it directly from the Downloads section.
PM> Install-Package Aspose.Email.Cpp PM> Install-Package Aspose.Words.Cpp
Converting Email Messages to PDF using C++
The following are the steps to convert email files to PDF format using C++.
- Load the email file using the MailMessage class.
- Save the email message in the MemoryStream as MHTML.
- Create an instance of the LoadOptions class.
- Set the load format as MHTML.
- Load the file from the MemoryStream using the Document(SharedPtr stream, SharedPtr loadOptions) constructor of the Document class.
- Save the email as a PDF file using the Document->Save(String fileName, SaveFormat saveFormat) method.
The following code sample shows how to convert email messages to PDF format.
Get a Free License
You can try the API without evaluation limitations by requesting a free temporary license.
In this article, you have learned how to convert email messages to PDF format using C++. For this, we have used Aspose.Email for C++ for loading the email and Aspose.Words for C++ for converting it to PDF. Both of these APIs provide numerous features for working with email and MS Word files. To explore these APIs in detail, you can visit their official documentation.