Reading items from Outlook

This came up a few weeks ago, so I wrote up some sample code for a developer. This is a quick-n-dirty way to read items from an Exchange mailbox:
    using Microsoft.Office.Interop.Outlook;
Then the code:

    ApplicationClass application = new ApplicationClass();

    NameSpaceClass namespaceClass = (NameSpaceClass)application.GetNamespace("MAPI");

    MAPIFolder folder = namespaceClass.GetDefaultFolder(OlDefaultFolders.olFolderInbox);

    Items outlookItems = folder.Items;


    // IMPORTANT: array is 1-based, not 0-based

    for (int itemNumber = 1; itemNumber < outlookItems.Count; itemNumber++)


        if (outlookItems[itemNumber] is MailItem)


            MailItem mailItem = outlookItems[itemNumber] as MailItem;

            string subject = mailItem.Subject;

            string messageBody = mailItem.HTMLBody;




Posted in General, Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s


Enter your email address to follow this blog and receive notifications of new posts by email.

Join 9 other followers

%d bloggers like this: