Export (0) Print
Expand All

How to: Retrieve Unread Messages from the Inbox

Applies to

The information in this topic applies only to the specified Visual Studio Tools for Office projects and versions of Microsoft Office.

Project type

  • Application-level projects

Microsoft Office version

  • Outlook 2003

  • Outlook 2007

For more information, see Features Available by Application and Project Type.

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

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));
}

Community Additions

ADD
Show:
© 2014 Microsoft