Outlook Programming: How to retrieve unread messages from any Outlook folder?
Recently one of my customer updated that he got a requirement to programmatically retrieve unread messages from any Outlook folder to be implemented part of his application. We tried the following steps - Will show you how you can programmatically retrieve unread messages from any Outlook folder using Outlook Object Model (OOM) API.
Let we first have a look at the following code snippet (C#.Net):
Outlook.MAPIFolder Fldr = this.Application.ActiveExplorer().Session.GetDefaultFolder
_(Outlook.OlDefaultFolders.olFolderInbox);
Outlook.Items UnReads = Fldr.Items.Restrict("[Unread]=true");
MessageBox.Show(string.Format("Unread items in Inbox = {0}", UnReads.Items.Count));
Line # 1, we need to specify target Outlook folder that we need to read messages. Here I used Inbox.
Line # 2, we need to filter target folder items using Restrict filter as Unread]=true to get unread items
Line # 3, displaying the number of unread items.
Please note: In order to retrieve unread messages from any Outlook folder, just point out the target folder in the Line # 1, instead of Inbox.
Pretty simple isn’t it
Comments
- Anonymous
April 07, 2014
can you please tell me how to use MAPI to create an application for fetching an e-mail from outlook using win32 programming in visual studio 8