This gist explains the steps and code snippet on how to convert EML to MSG 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 MSG format using Aspose.Email Cloud SDK for .NET.
For more information, please visit
This gist contains code snippets related to conversion of EML to MSG 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 MSG file | |
string resultantFile = "converted.msg"; | |
// format of resultant file | |
string toFormat = "Msg"; | |
try | |
{ | |
// read the sourec EML to stream object | |
using (var file = System.IO.File.OpenRead(@"C:\Users\shahbnay\Downloads\" + name)) | |
{ | |
// upload source EML file to Cloud storage | |
emailApi.CloudStorage.File.UploadFile(new Aspose.Email.Cloud.Sdk.Model.UploadFileRequest(name, file)); | |
// create EmailGetAsFileRequest instance by passing input file and resultant format | |
var convertRequest = new EmailGetAsFileRequest(name, toFormat); | |
// Perform the conversion operation | |
var response = emailApi.Email.GetAsFile(convertRequest); | |
// print success message if conversion is successful | |
if (response != null && response.Equals("OK")) | |
{ | |
// print the success message | |
Console.WriteLine("Successfully converted EML to MSG !"); | |
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(); | |
} |