Here's how to read emails from Outlook using C#

You would like to build an application/addin that reads outlook mail and notify the user or would like to do some other operations based on your business need. For this, you will need to use the Microsoft Outlook APIs.


Today we are going to see, how this can be done using the Microsoft.Office.Interop.Outlook.dll to read the email from Outlook context and extract the data.


Here's how to read emails from Outlook using C# (www.kunal-chowdhury.com)


Most of the people uses Microsoft Outlook to read and responds to mails, either in office environments or personally. If you are going to build an app or and addin for Outlook, you will need to read the mails.


First you need to add the reference of Microsoft.Office.Interop.Outlook.dll file in your project. Then create the outlook application and get the MAPI namespace. Now grab the folder where you want to search for the mails.


Application outlookApplication = new Application();
NameSpace outlookNamespace = outlookApplication.GetNamespace("MAPI");
MAPIFolder inboxFolder = outlookNamespace.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
Items mailItems = inboxFolder.Items;


In the above example, we have seen how to read the mail items present in the Inbox root folder. If you want to read mails present in root of Sent Items, Deleted Items etc. you can specify it using the Microsoft.Office.Interop.Outlook.OlDefaultFolders enum values. Here's the different values that the enum provides:


namespace Microsoft.Office.Interop.Outlook
    public enum OlDefaultFolders
        olFolderDeletedItems = 3,
        olFolderOutbox = 4,
        olFolderSentMail = 5,
        olFolderInbox = 6,
        olFolderCalendar = 9,
        olFolderContacts = 10,
        olFolderJournal = 11,
        olFolderNotes = 12,
        olFolderTasks = 13,
        olFolderDrafts = 16,
        olPublicFoldersAllPublicFolders = 18,
        olFolderConflicts = 19,
        olFolderSyncIssues = 20,
        olFolderLocalFailures = 21,
        olFolderServerFailures = 22,
        olFolderJunk = 23,
        olFolderRssFeeds = 25,
        olFolderToDo = 28,
        olFolderManagedEmail = 29


Once you have fetched the mail items out of the selected mail box, iterate through them, as shown in the below code snippet:


foreach (MailItem item in mailItems)
    stringBuilder.AppendLine("From: " + item.SenderEmailAddress);
    stringBuilder.AppendLine("To: " + item.To);


Don't forget to release the COM objects properly. You have to call 'Marshal.ReleaseComObject' method to release them. If you need the entire code from the sample shown above, here it is for your reference:


private static void ReadMailItems()
    Application outlookApplication = null;
    NameSpace outlookNamespace = null;
    MAPIFolder inboxFolder = null;
    Items mailItems = null;
        outlookApplication = new Application();
        outlookNamespace = outlookApplication.GetNamespace("MAPI");
        inboxFolder = outlookNamespace.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
        mailItems = inboxFolder.Items;
        foreach (MailItem item in mailItems)
            var stringBuilder = new StringBuilder();
            stringBuilder.AppendLine("From: " + item.SenderEmailAddress);
            stringBuilder.AppendLine("To: " + item.To);
            stringBuilder.AppendLine("CC: " + item.CC);
            stringBuilder.AppendLine("Subject: " + item.Subject);
    catch { }
private static void ReleaseComObject(object obj)
    if (obj != null)
        obj = null;


Hope the information and the code shared above is helpful. Make sure to release COM objects as mentioned above. Remember that, the code will execute only when Outlook is installed in the user system as the referenced dll (i.e. Microsoft.Office.Interop.Outlook.dll) is a wrapper on top of Outlook.exe file. If you have any queries/issues let me know. Have a great day ahead!



Kunal Chowdhury
If you have come this far, it means that you liked what you are reading (Here's how to read emails from Outlook using C#).
Why not reach little more and connect with me directly on Twitter, Facebook, Google+ and LinkedIn. I would love to hear your thoughts and opinions on my articles directly.

Don't forget to share your feedback/queries in the comment section below.