We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Email messages to PDF

Please advise as of how can we use Aspose to print email (Outlook) messages (The main message, not the attachments).

This message was posted using Page2Forum from Word to Pdf - Aspose.Pdf for .NET and Java

Correction: by “print” I meant “convert to PDF”.

Dear Manuel,

Aspose.Network deals with viewing and converting etc. Outlook email messages. That's why, i have moved your inquiry here so that Aspose.Network team can share their comments about it.

Have a good time.

Hi Manuel,

There is no direct method of printing .msg file to pdf, but you can use the following code create a pdf document from the msg file. This code uses Aspose.Network and Aspose.Pdf libraries.

You can modify the code to include other details if required.

public string strOutlookFile = "c:\\outlook.msg";

public string strPdfFile = "c:\\outlook.pdf";

// load the message

MailMessage mail = MailMessage.Load(strOutlookFile, MessageFormat.Msg);

// create the header and body

StringBuilder sb = new StringBuilder();

sb.AppendLine("From:\t\t" + mail.From.ToString());

sb.AppendLine("Sent:\t\t" + mail.Date.ToLongDateString() + " " + mail.Date.ToLongTimeString());

sb.AppendLine("To:\t\t" + mail.To.ToString());

if (mail.CC.Count >= 0)

sb.AppendLine("Cc:\t\t" + mail.CC.ToString());

sb.AppendLine("Subject:\t" + mail.Subject);

sb.AppendLine(); sb.AppendLine(); sb.AppendLine(); sb.AppendLine();

// create pdf doc

Aspose.Pdf.Pdf pdf1 = new Aspose.Pdf.Pdf();

Aspose.Pdf.Section sec1 = pdf1.Sections.Add();

// create text paragraph

Aspose.Pdf.Text text = new Aspose.Pdf.Text(sb.ToString() + mail.TextBody);

// save pdf file