This gist explains the steps and code snippet on how to convert EML to MHT format using Aspose.Email Cloud SDK for .NET.
For more information, please visit
This gist explains the steps and code snippet on how to convert EML to MHT format using Aspose.Email Cloud SDK for .NET.
For more information, please visit
This gist contains code snippets related to conversion of EML files to MHT format using Aspose.Email Cloud SDK for .NET |
// For complete examples and data files, please go to | |
https://github.com/aspose-email-cloud/aspose-email-cloud-dotnet | |
// Get client credentials from https://dashboard.aspose.cloud/ | |
string clientSecret = "d757548a9f2558c39c2feebdf85b4c44"; | |
string clientID = "4db2f826-bf9c-42e7-8b2a-8cbca2d15553"; | |
// create an instance of EmailCloud Api | |
var emailApi = new EmailCloud(clientSecret, clientID); | |
// source EML file name | |
string name = "sample.eml"; | |
// name of resultant MHT file | |
string resultantFile = "converted.mht"; | |
// format of input email file | |
string fromFormat = "eml"; | |
// format of resultant file | |
string toFormat = "Mhtml"; | |
try | |
{ | |
// read the sourec EML to stream object | |
using (var file = System.IO.File.OpenRead(@"C:\Users\shahbnay\Downloads\" + name)) | |
{ | |
// create EmailConvert request instance passing input, output formats and file stream | |
var convertRequest = new EmailConvertRequest(fromFormat, toFormat, file); | |
// Perform the conversion operation | |
var response = emailApi.Email.Convert(convertRequest); | |
// print success message if conversion is successful | |
if (response != null && response.Equals("OK")) | |
{ | |
// print the success message | |
Console.WriteLine("Successfully converted EML to MHT !"); | |
Console.ReadKey(); | |
} | |
// save the resultant file stream to local drive | |
saveToDisk(response, @"C:\Users\shahbnay\Downloads\" + resultantFile); | |
} | |
}catch (Exception ex) | |
{ | |
// print the exception in console | |
Console.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace); | |
} | |
// custom method to save the output to system drive | |
static void saveToDisk(Stream responseStream, String resultantFile) | |
{ | |
var fileStream = File.Create(resultantFile); | |
responseStream.Seek(0, SeekOrigin.Begin); | |
responseStream.CopyTo(fileStream); | |
fileStream.Close(); | |
} |