Free Support Forum - aspose.com

Convert msg document to pdf

I have .msg files saved to the file system.

I need to convert these files to pdf.

I have seen that with Aspose.Words and Aspose.Cells, it's very simple to save doc and xls files to pdf, but declaring a new email message does not let me give it a file location (that i can tell so far).

Could you point me in the right direction?

Thank you,

lshaffer

Hi Latisha,


Thank you for using Aspose.Email.

Well, currently Aspose.Email can not convert MSG files directly to PDF and you need to use Aspose.Words in combination with Aspose.Email to achieve this. Please have a look at the following code sample for your reference. I have also attached the sample MSG and output PDF files here for your reference. Please feel free to contact us if you have any additional inquiry/query related to Aspose.Email. We’ll be glad to assist you further.

Sample Code:

MailMessage mailMsg = MailMessage.Load(“About
Aspose.msg”
);<o:p></o:p>

MemoryStream ms = new MemoryStream();

mailMsg.Save(ms, MailMessageSaveType.MHtmlFromat);

//create an instance of LoadOptions and set the LoadFormat to Mhtml

var loadOptions = new Aspose.Words.LoadOptions();

loadOptions.LoadFormat = LoadFormat.Mhtml;

//create an instance of Document and load the MTHML from MemoryStream

var document = new Aspose.Words.Document(ms, loadOptions);

//create an instance of PdfSaveOptions and set the SaveFormat to PDF

var saveOptions = new Aspose.Words.Saving.PdfSaveOptions();

//save the document to PDF file

document.Save("About Aspose.pdf", saveOptions);

Thank you very much!!

That is exactly what I needed!

lshaffer

Hi Ishaffer,


You are welcome, and please feel free to write to us if you have any additional query/inquiry related to Aspose.Email. We’ll be glad to help you further.