Email to MHT

Microsoft Outlook and other popular email clients use EML (MIME RFC 822 standard) as a standard format. EML is the abbreviation for electronic mail or email. Similarly, it is a file extension for an email message saved to a file in the Internet Message Format protocol for electronic mail messages. The EML files usually contain plain ASCII text for the main message body, headers and hyperlinks, and attachments. However, there is one threat associated with the EML format is that it can be a phishing email and the attachment could either: Infect your machine with malware if you open the attachment.

Furthermore, if we save an offline copy of these files, the malware can easily affect them and data can be lost. Also, in order to open EML files, we need a supported application (Microsoft Outlook 365, Microsoft Windows Mail, Mozilla Thunderbird, etc.). So a preemptive measure can be its conversion to MHT format.

Free Email Processing API

Aspose.Email Cloud is our award-winning API offering the capabilities to create, manipulate and transform popular Email formats to other supported formats. So create your own cloud-based email management solution supporting OAuth and send simple or MIME email messages with or without attachments. Access API on any platform including Windows, Linux, macOS, and in any application type i.e. Desktop, Mobile, Web, hybrid, etc.

In order to directly use the API within a programming language, please try using our language-specific Cloud SDK which is a wrapper around Cloud SDK. In this article, we are going to focus on the conversion of EML files to MHT format using Aspose.Email Cloud SDK for .NET. In order to use the SDK, you need to have one of the supported (or compatible with supported) .NET frameworks:

  • .NETFramework 2.0
  • .NETFramework 4.5.2
  • .NETStandard 2.0
  • MonoAndroid 6.0
  • Xamarin.iOS 1.0
  • Xamarin.Mac 2.0

Installation

In order to use the Cloud SDK, the first step is its installation. It is available for download at NuGet and GitHub. Please execute the following command in the terminal window to perform the installation for NuGet:

nuget install Aspose.Email-Cloud

When using .NET CLI:

dotnet add package Aspose.Email-Cloud

If you are using Visual Studio, then the package can also be installed using Package Manager Console. Please execute the following command:

PM> Install-Package Aspose.Email-Cloud
Image 1:- Aspose.Words NuGet package installed.

Image 1:- Aspose.Words NuGet package installed.

NuGet Package Manager – Visual Studio

Another easiest approach is to install the SDK via NuGet Package Manager within Visual Studio IDE.

  1. Open the Solution Explorer.
  2. Expand the project and Right-click Packages folder within your solution.
  3. Select Manage NuGet Packages… option
  4. Click on the Browse tab and search for “Aspose.Email-Cloud
  5. Click on the Aspose.Email-Cloud package, select the appropriate version in the right-tab and click Add Package button
Image 2:- Aspose.Words Package in NuGet Package Manager.

Image 2:- Aspose.Words Package in NuGet Package Manager.

Cloud Account Subscription

Our APIs are only accessible to authorized persons because the data stored in cloud storage is accessible via Cloud APIs. The subscription is free and no upfront payment details are required. Perform up to 150 free document processing operations. So once you are satisfied with the capabilities of API, you may consider opting for a license subscription which can be as low as $0.005 / API call. For further details, please visit Pricing.

Now proceed with account creation by visiting Aspose.Cloud dashboard. No credit card or other payment details are required. If you have GitHub or Google account, simply Sign Up or, click on the create a new account button and provide the required information. Now login to the dashboard using credentials and expand the Applications section from the dashboard and scroll down towards the Client Credentials section to see Client ID and Client Secret details.

Client Credentials

Image 3:- Client Credentials at Aspose.Cloud dashboard.

EML to MHT in C#

Please follow the steps given below to convert the EML file to MHT format using C# .NET.

  • The first step is to create an object of EmailCloud class by passing ClientID and Client Secret details as arguments
  • Secondly, read source email file to File.OpenRead instance
  • Thirdly, create an instance of EmailConvertRequest while passing input file format, resultant file format and stream object holding input EML file
  • Now call Email.Convert(…) method to initiate the conversion operation
  • Finally, call custom method to save resultant file to local drive using File.Create instance
EML to MHT preview

Image 4:- EML to MHT conversion preview.

The files used in the above example can be downloaded from sample.eml and converted.mht.

Converting EML to MHT using cURL

Since Aspose.Email Cloud is developed according to REST architecture, so it can easily be accessed via cURL commands. Use the terminal application/command prompt to access the APIs. So the first step is to generate a JWT access token based on client credentials specified over Aspose.Cloud dashboard. Please execute the following command to generate the JWT token.

curl -v "https://api.aspose.cloud/connect/token" \
 -X POST \
 -d "grant_type=client_credentials&client_id=4db2f826-bf9c-42e7-8b2a-8cbca2d15553&client_secret=d757548a9f2558c39c2feebdf85b4c44" \
 -H "Content-Type: application/x-www-form-urlencoded" \
 -H "Accept: application/json"

Now we are going to discuss the steps of using the cURL command to convert .eml files already available in Cloud storage to MHTML format. The output is saved on the system using the -o parameter.

curl -X GET "https://api.aspose.cloud/v4.0/email/as-file?fileName=sample.eml&format=Mhtml" \
-H  "accept: multipart/form-data" \
-H  "authorization: Bearer <JWT Token>" \
-o resultant.mht

In case you need to perform the conversion of the .eml file to be uploaded from the local drive, please try using the following cURL command:

curl -X PUT "https://api.aspose.cloud/v4.0/email/convert?fromFormat=Eml&toFormat=Mhtml" \
-H  "accept: multipart/form-data" \
-H  "authorization: Bearer <JWT Token>" \
-H  "Content-Type: multipart/form-data" \
-d @sample.eml \
-o converted.mht

Conclusion

In this article, we have highlighted the features of Aspose.Email Cloud for popular email formats processing. The API enables you to create email manipulation applications to apply red flags to email messages, apply email attachments as well as download email attachments, and much more. We have discussed the steps on how to perform the EML files to MHT conversion using C# .NET and the cURL commands. Furthermore, the .NET Cloud SDK is developed as per the MIT license. Download and customize them absolutely free of charge. The complete source code is available over GitHub.

We have also provided a swagger view of Cloud APIs so that you can test the APIs within a web browser. Furthermore, if you encounter any issues or you have any further queries, please feel free to contact us through the free customer support forum.

We also recommend visiting the following links to learn more about: