How to convert an MSG Outlook File to PDF Document in C# .NET Framework

MSG format is infamous for its incompatibility as well as the difficulty in parsing it. If you want to know what true suffering is, then give that a whirl with the manual approach. If you would rather have your sanity and your afternoon left intact, then I have a means of getting this done very fast using an API. Let me demonstrate for you how this works.

We start by downloading our package:

Install-Package Cloudmersive.APIClient.NET.DocumentAndDataConvert -Version 3.2.8

Next we go ahead with our function call, like so:

using System;using System.Diagnostics;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Api;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Client;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Model;namespace Example{public class ConvertDocumentMsgToPdfExample{public void main(){// Configure API key authorization: ApikeyConfiguration.Default.AddApiKey("Apikey", "YOUR_API_KEY");// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed// Configuration.Default.AddApiKeyPrefix("Apikey", "Bearer");var apiInstance = new ConvertDocumentApi();var inputFile = new System.IO.Stream(); // System.IO.Stream | Input file to perform the operation on.var bodyOnly = true;  // bool? | Optional; If true, the HTML string will only include the body of the email. Other information such as subject will still be given as properties in the response object. Default is false. (optional)try{// Convert Email MSG file to PDF documentbyte[] result = apiInstance.ConvertDocumentMsgToPdf(inputFile, bodyOnly);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling ConvertDocumentApi.ConvertDocumentMsgToPdf: " + e.Message );}}}}

And that’s all that needs to be done.

Written by

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store