Amélie
Amélie

Reputation: 119

Outlook : Get unread emails

I am using Outlook in my app. To have the number of unread mails, I use "UnreadItemCount". To have the number of unread mails, I use:

   Inbox: MAPIFolder;
   NewMail: boolean;
   Item: TListItem;

  outlook, NameSpace , aMailItem : OLEVariant;
  i : integer;

const
  olFolderInbox = $00000006;
begin

OutlookApplication1.CreateObject('Outlook.Application');
NmSpace := OutlookApplication1.GetNameSpace('MAPI');
NmSpace.Logon('', '', False, False);

Inbox := NmSpace.GetDefaultFolder(olFolderInbox);
NewMail := (Inbox.UnreadItemCount > 0);
ShowMessage('Number of unread emails: ' + inttostr(Inbox.UnreadItemCount));

I want to have unread emails. That is, the list of emails with the property Unread or: UnRead = true.
is there a way to do this please?
Thanks for your help

Upvotes: 1

Views: 335

Answers (1)

Dmitry Streblechenko
Dmitry Streblechenko

Reputation: 66235

Call MAPIFolder.Items.Restrict (returns Items collection) with a query like [Unread] = true

Upvotes: 2

Related Questions