Export EMAIL to PDF via .NET

.NET API to Render EMAIL to PDF on Windows, macOS, and Linux without using Word or Outlook

 

If you are a .NET developer looking to add EMAIL to PDF conversion features inside your applications, Aspose.Total for .NET file format manipulation APIs are the way forward. By using Aspose.Email for .NET , you can convert EMAIL file format to HTML. After that, by using Aspose.Words for .NET , you can render HTML to PDF.

C# API to Convert EMAIL to PDF

  1. Open EMAIL file using MailMessage class
  2. Convert EMAIL to HTML by using Save method
  3. Load HTML by using Document class
  4. Save the document to PDF format using Save method and set Pdf as SaveFormat

Get Started with .NET File Format APIs

Install from command line as nuget install Aspose.Total or via Package Manager Console of Visual Studio with Install-Package Aspose.Total.

Alternatively, get the offline MSI installer or DLLs in a ZIP file from downloads .

MailMessage message = MailMessage.Load("sourceFile.msg");
// save EMAIL as a HTML 
message.Save("HtmlOutput.html", SaveOptions.DefaultHtml);
// load HTML with an instance of Document
Document document = new Document("HtmlOutput.html");
// call save method while passing SaveFormat.Pdf
document.Save("output.pdf", SaveFormat.Pdf); 

Parse EMAIL File via .NET

Before converting EMAIL to PDF, if you want to make sure that you are converting the correct email, you can load EMAIL document, parse it and have a look at your desired property. By using MapiMessage class of Aspose.Email for .NET API, you can get sender and recipients information. For example, you can check for a specific sender email for the conversion by using SenderName property.

var outlookMessageFile = MapiMessage.FromFile("message.msg");
// check for SenderName 
if(outlookMessageFile.SenderName == "John"){
    //proceed with conversion process
}

Restrict PDF Document Editing via .NET

While saving the document from EMAIL to PDF, you might need to protect your output document. Sometimes you may need to limit the ability to edit a document and only allow certain actions with it. This can be useful to prevent other people from editing sensitive and confidential information in your document. Aspose.Words for .NET API, enables you to control the way you restrict the content using the ProtectionType enumeration parameter. You can set your document to read-only by using the following lines of code.

Document document = new Document("HtmlOutput.html");
// apply document protection and set protection password
doc.Protect(ProtectionType.ReadOnly, "password");
// call save method while passing SaveFormat.Pdf
document.Save("output.pdf", SaveFormat.Pdf);  

Other Conversion Options

MSG TO OTT (OpenDocument Standard Format)
MSG TO DOT (Microsoft Word Template Files)
MSG TO MD (Markdown Language)
MSG TO ODT (OpenDocument Text File Format)
MSG TO PCL (Printer Command Language Document)
MSG TO PS (PostScript File)
MSG TO SVG (Scalar Vector Graphics)
MSG TO DOCX (Office 2007+ Word Document)
MSG TO DOTM (Microsoft Word 2007+ Template File)
MSG TO DOCM (Microsoft Word 2007 Marco File)
MSG TO JPEG (Joint Photographic Expert Group)
MSG TO RTF (Rich Text Format)
MSG TO PNG (Portable Network Graphic)
MSG TO XPS (XML Paper Specifications)
MSG TO WORDML (Microsoft Word 2003 WordprocessingML)
MSG TO BMP (Bitmap Image File)
MSG TO EPUB (Open eBook File)
MSG TO DOC (Microsoft Word Binary Format)
MSG TO EMF (Enhanced Metafile Format)
MSG TO DOTX (Microsoft Word Template File )
MSG TO TIFF (Tagged Image File Format)
MSG TO GIF (Graphical Interchange Format)

MSG What is MSG File Format?

MSG is a file format used by Microsoft Outlook and Exchange to store email messages, contact, appointment, or other tasks. Such messages may contain one or more email fields, with the sender, recipient, subject, date, and message body, or contact information, appointment particulars, and one or more task specifications. The properties that constitute the Message object, including are also a part of the MSG file.  MSG file has headers, main message body, and hyperlinks as plain ASCII text. MSG files are also suitable with the programs that need Microsoft’s Messaging Applications Programming Interface (MAPI).

Read More

PDF What is PDF File Format?

Portable Document Format (PDF) is a type of document created by Adobe back in 1990s. The purpose of this file format was to introduce a standard for representation of documents and other reference material in a format that is independent of application software, hardware as well as Operating System. PDF files can be opened in Adobe Acrobat Reader/Writer as well in most modern browsers like Chrome, Safari, Firefox via extensions/plug-ins. Most of the commercially available software suites also offer conversion of their documents to PDF file format without the requirement of any additional software component.

Read More