Convert Outlook message file(MSG) to PDF in C# .NET using Aspose.Email REST API

Hi,


I am hoping to use Aspose’s Email Cloud API to convert a .msg file (an outlook message file) to a pdf. I welcome your pointers to achieve this.

Regards,
Dave

Hi Dave,


Thank you for writing to Aspose support team.

Aspose.Email for Cloud can be used to convert email messages to MHT only. Conversion to PDF is not supported by the API as it lies outside the scope of the API. However, you may check Aspose.Words for Cloud API which further allows converting the generated MHTML to PDF. Please feel free to write to write us back if you have any additional query/inquiry in this regard.

This helps. Thanks. Here is my first attempt using the .Net SDK


var path = Path.GetTempFileName();
var sourcePath = path + “.source”;
File.WriteAllBytes(sourcePath, page);
var root = new Folder();
root.UploadFile(sourcePath, “”);
// need more than a test key to get this to return meaningful content, I suspect
var strUri = Product.BaseProductUri + “/email/” + Path.GetFileName(sourcePath) + “?format=mht”;
var signedUri = Utils.Sign(strUri);
var responseStream = Utils.ProcessCommand(signedUri, “GET”);
var fileStream = new MemoryStream();
Utils.CopyStream(responseStream, fileStream);
responseStream.Close();
File.WriteAllBytes(sourcePath, fileStream.ToArray());
var converter = new global::Aspose.Cloud.Words.Converter();
converter.ConvertLocalFile(sourcePath, path, global::Aspose.Cloud.Words.SaveFormat.Pdf);
var pdfBytes = File.ReadAllBytes(path);
PdfConvert.AppendPdf(pdfBytes, document, writer);
File.Delete(sourcePath);
File.Delete(path);

Hi Dave,


Its good to know that you were able to get started with the suggested link. Please feel free to write to us in case you have any other query/inquiry. We’ll be glad to assist you further.