如何:检索收件箱中的未读邮件

更新:2007 年 11 月

适用对象

本主题中的信息仅适用于指定的 Visual Studio Tools for Office 项目和 Microsoft Office 版本。

项目类型

  • 应用程序级项目

Microsoft Office 版本

  • Outlook 2003

  • Outlook 2007

有关更多信息,请参见按应用程序和项目类型提供的功能

本示例从 Outlook“收件箱”中检索未阅读的电子邮件并显示项数。

示例

Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
    Dim inbox As Outlook.MAPIFolder = _
        Me.Application.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.Session.GetDefaultFolder
        (Outlook.OlDefaultFolders.olFolderInbox);

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

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

请参见

任务

如何:创建电子邮件项

如何:以编程方式发送电子邮件

如何:在收到电子邮件后执行操作

概念

使用邮件项

应用程序级外接程序编程入门