With dedicated posts on how to connect an application through its API, from a NET6 application written in C#.
As we’ve said before, integrating different technologies is a very necessary skill in the field of IoT. Previously, we’ve seen how to connect with Microsoft Word and Microsoft Excel. This time, we’ll connect with Outlook.
Just as we’ve seen in the other posts in the series, being able to connect to Outlook doesn’t mean it will be the best option for our project. In particular, there are better ways to establish communication, and even to send emails, than using the Outlook API.
But in certain cases, it’s a project requirement to do it specifically in Outlook. For example, if we want to display the Outlook screen with the generated email before sending it, or if we want to add an appointment to a calendar.
In any case, it’s a quite interesting example of API usage and technology integration, which is the goal of this series. So, let’s get to it!
How to Connect to Microsoft Outlook with a NET6 Application
We start the example by creating a simple console application in NET6. We add the “Microsoft Outlook xx.0 Object Library” as a ‘COM’ reference, where xx will be the version of Microsoft Outlook you have installed on your computer.
In the case of Microsoft Outlook, we need to do a step we didn’t have with Word and Excel, which is to allow programmatic access. To do this, enable the option in Options -> Trust Center -> Programmatic Access.
Next, we paste this code into our console application.
using Microsoft.Office.Interop.Outlook;
using OutlookApp = Microsoft.Office.Interop.Outlook.Application;
OutlookApp outlookApp = new OutlookApp();
MailItem mailItem = outlookApp.CreateItem(OlItemType.olMailItem);
mailItem.To = "[email protected]";
mailItem.Subject = $"Subject";
mailItem.HTMLBody = "";
mailItem.Display(false);
mailItem.Send();
Console.ReadLine();
The Microsoft Outlook documentation is not as good as Excel’s and Word’s, but I’ll leave a link just in case from Visual Basic https://learn.microsoft.com/es-es/office/vba/outlook/concepts/getting-started/automating-outlook-from-a-visual-basic-application. It’s not too difficult to translate the concepts.
With the .NET API for Microsoft Outlook, we can query received emails, create new emails, attach files, query the calendar, create new appointments, and in general any option we could do manually.
And that’s it for the part of the series dedicated to Microsoft Office applications. In the next post in the series, we’ll move on to CAD applications, looking at the SolidWorks API.
Download the Code
All the code from this post is available for download on Github.

