Share via


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.

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")

    MessageBox.Show( _
        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: Create an E-Mail Item

How to: Send E-Mail Programmatically

How to: Perform Actions When an E-Mail Message Is Received

Concepts

Working with Mail Items

Getting Started Programming Application-Level Add-Ins