Introduction

In this post, we will look at the parsing of table containing inside outlook email body using .NET C#, EWS Managed API and HtmlAgilitypack.EWS (Web service in exchange) allow us to access Microsoft Exchange such as EMAIL, Contacts, Calendar. For more details about EWS, visit this link.

Background

This tips is for developers, tech leads and tech community.

Open Visual Studio 2017 Community Edition

Open Visual Studio 2017, Go To New -> Project. Select Visual C# -> Windows Classic desktop from the left hand navigation and select project type as ConsoleApp(.NET Framework). Enter the project name as ParseOutlookContents.

.

Installing HtmlAgilityPack and Microsoft.Exchange.WebServices

We will then add the HtmlagilityPack and Microsoft.Exchange.WebServices libraries in our project using the NuGet Package Manager which makes it very easy to install the libraries in our project.

Right click on project > select Manage Nuget Packages and search for HtlmagilityPack and Microsoft.Exchange.WebServices in browse tab. Install both the libraries in the project.

.

After adding libraries, expand project references folder and see whether the libraries are added in reference folder.

Open program.cs and add the following namespace on the top.

// Using Microsoft.Exchange.WebServices.Data;// Using Htmlagilitypack;

This code is reading HTML table containing inside email body from inbox custom folder "Saurav" and rendering it into datatable. However, we can read content from Outbox, Calendar, Draft respectively. But in the code, we need to make changes accordingly.

Folder rootfolder = Folder.Bind(service, WellKnownFolderName.Outbox);

Select the options from WellKnownFolderName enums as per your requirement.

Conclusion

The purpose of this article is to demonstrate how easily you can render HTML table from Outlook email body into datatable using .NET C#. In the next article, we will discuss about the implementation of similar requirement in .NET Core.