Programmatically retrieve unread messages from the Inbox
This example retrieves unread email messages from the Outlook Inbox and displays the number of items.
Applies to: The information in this topic applies to VSTO Add-in projects for Outlook. For more information, see Features available by Office application and project type.
Example
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));
}
Related content
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for