Convert Emails and Outlook Messages to PDF using Node.js

You can easily convert your emails and Outlook messages to PDF documents using Node.js on the cloud. Conversion of emails and Outlook messages to PDF enables you to keep records or share important emails and attachments in a portable form. As a Node.js developer, you can convert EML and MSG files to PDF documents programmatically. In this article, you will learn how to convert EML and MSG files to PDF documents using a REST API in Node.js.

The following topics shall be covered in this article:

EML to PDF Conversion REST API and Node.js SDK

For converting EML and MSG files to PDF, I will be using the Node.js SDK of GroupDocs.Conversion Cloud API. It is a platform-independent document and image conversion solution. It allows you to seamlessly convert your documents and images of any supported file format to any format you need. You can easily convert between over 50 types of documents and images such as Word, PowerPoint, Excel, PDF, HTML, CAD, raster images, etc. It also provides .NET, Java, PHP, Ruby, Android, and Python SDKs as its document conversion family members for the Cloud API.

You can install GroupDocs.Conversion Cloud to your Node.js project using the following command in the console:

npm install groupdocs-conversion-cloud

Please get your Client ID and Client Secret from the dashboard before you start following the steps and available code examples. Once you have your ID and secret, please add in the code as shown below:

Convert EML to PDF using a REST API in Node.js

You can convert your emails to PDF documents programmatically on the cloud by following the simple steps given below:

  1. Upload the EML file to the cloud
  2. Convert EML to PDF using Node.js
  3. Download the converted PDF file

Upload the EML File

Firstly, upload the EML file to the cloud using the following code sample:

As a result, the uploaded EML file will be available in the files section of your dashboard on the cloud.

Convert EML to PDF using Node.js

You can easily convert emails from EML files to PDF documents programmatically by following the steps mentioned below:

  • Create an instance of the ConvertApi
  • Create an instance of the ConvertSettings
  • Set the EML file path
  • Assign “pdf” to the format
  • Create an instance of the EmlLoadOptions
  • Set various properties such as displayHeader, displayEmailAddress, etc.
  • Assign EmlLoadOptions to ConvertSettings
  • Create an instance of the PdfConvertOptions
  • Set various properties such as centerWindow, MarginTop, MarginLeft, etc.
  • Assign PdfConvertOptions to ConvertSettings
  • Provide the output file path
  • Create ConvertDocumentRequest with ConvertSettings
  • Convert by calling the convertDocument() method with ConvertDocumentRequest

The following code example shows how to convert an EML file to a PDF document using a REST API in Node.js.

Convert EML to PDF using a REST API in Node.js

Convert EML to PDF using a REST API in Node.js

Download the Converted File

The above code sample will save the converted PDF file on the cloud. You can download it using the following code sample:

MSG to PDF Conversion using REST API in Node.js

You can easily convert Outlook MSG files to PDF documents programmatically by following the steps mentioned below:

  • Create an instance of the ConvertApi
  • Create an instance of the ConvertSettings
  • Set the MSG file path
  • Assign “pdf” to the format
  • Provide the output file path
  • Create an instance of the MsgLoadOptions
  • Set various properties such as displayCcEmailAddress, displayBccEmailAddress, etc.
  • Assign load options to ConvertSettings
  • Create ConvertDocumentRequest with ConvertSettings
  • Convert by calling the convertDocument() method with ConvertDocumentRequest

The following code example shows how to convert an MSG file to a PDF document using a REST API in Node.js. Please follow the steps mentioned earlier to upload and download a file.

MSG to PDF Conversion using REST API in Node.js

MSG to PDF Conversion using REST API in Node.js

Convert Email Attachments to PDF using REST API in Node.js

You can easily convert email attachments to PDF documents programmatically by following the steps mentioned below:

  • Create an instance of the ConvertApi
  • Create an instance of the ConvertSettings
  • Set the MSG file path
  • Assign “pdf” to the format
  • Provide the output file path
  • Create an instance of the MsgLoadOptions
  • Set the convertAttachments property to true
  • Assign load options to ConvertSettings
  • Create ConvertDocumentRequest with ConvertSettings
  • Convert by calling the convertDocument() method with ConvertDocumentRequest

The following code example shows how to convert email attachments to a PDF document using a REST API in Node.js. Please follow the steps mentioned earlier to upload and download a file.

Convert Email Attachments to PDF using REST API in Node.js

Convert Email Attachments to PDF using REST API in Node.js

Try Online

Please try the following free online EML to PDF and MSG to PDF conversion tools, which are developed using the above API.

Conclusion

In this article, you have learned how to convert emails and Outlook messages to PDF documents using Node.js on the cloud. You have also learned how to convert Outlook MSG files to PDF documents using Node.js. Moreover, you have learned how to convert email attachments to PDF documents programmatically. This article also explained how to programmatically upload the EML file on the cloud and then download the converted PDF file from the cloud. You can learn more about GroupDocs.Conversion Cloud API using the documentation. We also provide an API Reference section that lets you visualize and interact with our APIs directly through the browser. In case of any ambiguity, please feel free to contact us on the forum.

See Also