How to: Programmatically Retrieve Unread Messages from the Inbox

 

This example retrieves unread e-mail messages from the Outlook Inbox and displays the number of items.

Applies to: The information in this topic applies to VSTO add-in projects for Outlook. For more information, see Features Available by Office Application and Project Type.

        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            Outlook.MAPIFolder inbox =
                this.Application.ActiveExplorer().Session.GetDefaultFolder
                (Outlook.OlDefaultFolders.olFolderInbox);

            Outlook.Items unreadItems = inbox.
                Items.Restrict("[Unread]=true");

            MessageBox.Show(
                string.Format("Unread items in Inbox = {0}", unreadItems.Count));
        }

Working with Mail Items
Getting Started Programming VSTO Add-ins
How to: Programmatically Create an E-Mail Item
How to: Programmatically Send E-Mail Programmatically
How to: Programmatically Perform Actions When an E-Mail Message Is Received

Show: