Skip to content

Instantly share code, notes, and snippets.

@aspose-cloud
Last active October 20, 2021 21:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-cloud/2239c1e9b4be7abbe01930430ee42e21 to your computer and use it in GitHub Desktop.
Save aspose-cloud/2239c1e9b4be7abbe01930430ee42e21 to your computer and use it in GitHub Desktop.
This gist contains code snippets related to conversion of EML to MSG format using Aspose.Email Cloud SDK for .NET
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();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment