Compartir a través de


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 application-level projects for Outlook 2013 and Outlook 2010. For more information, see Features Available by Office Application and Project Type.

Example

Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
    Dim inbox As Outlook.MAPIFolder = _
        Me.Application.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)

    Dim unreadItems As Outlook.Items = _
    inbox.Items.Restrict("[Unread]=true")

    MsgBox(String.Format("Unread items in Inbox = {0}", unreadItems.Count))
End Sub
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));
}

See Also

Tasks

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

Concepts

Working with Mail Items

Getting Started Programming Application-Level Add-Ins