How to convert an MSG Outlook File to HTML String in C# .NET Framework

Outlook’s MSG is a notoriously difficult format to deal with, potentially containing one of three separate formats: RTF, HTML, or plain text. This multiplies the work involved, not to mention converting RTF into HTML is no cake-walk on its own. To help us cut through the busy work, we will be applying a Cloudmersive API that will let us finish in no time flat.

First we install our API client:

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

Next we call our conversion function:

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 ConvertDocumentMsgToHtmlExample{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 MSG. Other information such as subject will still be given as properties in the response object. Default is false. (optional)var includeAttachments = true;  // bool? | Optional; If false, the response object will not include any attachment files from the input file. Default is true. (optional)try{// Convert Email MSG file to HTML stringMsgToHtmlResult result = apiInstance.ConvertDocumentMsgToHtml(inputFile, bodyOnly, includeAttachments);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling ConvertDocumentApi.ConvertDocumentMsgToHtml: " + e.Message );}}}}

And done!

Image for post

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