HOW TO:以程式設計方式從收件匣中擷取未讀取的訊息
這個範例會從 Outlook 的 [收件匣] 擷取未讀取的電子郵件訊息並顯示項目數。
**適用於:**本主題中的資訊適用於 Outlook 2013 和 Outlook 2010 的應用程式層級專案。如需詳細資訊,請參閱依 Office 應用程式和專案類型提供的功能。
範例
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));
}