This project is read-only.

Total mails on folder

Topics: Help requests
May 16, 2014 at 1:16 PM
Hi,

Is there a way to quickly get just the number of all mails that a certain folder has, without fetching the messages?

Thank you in advance,

André Lucas
May 16, 2014 at 8:22 PM
Hi André,

in order to get the number of messages in a folder, you can use the Folder.Exists property.

If the client.Behavior.ExamineFolders property is set to true (it is by default), then you will be able to get number of messages right after connection. At any other point of time you can use the methods Folder.Examine or Folder.Status to update the information about the number of messages.

Getting the number of messages after connection:
var numberOfMessagesInInbox = client.Folders.Inbox.Exists;

Updating the number of messages using Folder.Examine:
client.Folders.Inbox.Examine();
var numberOfMessagesInInbox = client.Folders.Inbox.Exists;

Updating the number of messages using Folder.Status (better approach):
client.Folders.Inbox.Status(new[] { FolderStatusFields.Messages });
var numberOfMessagesInInbox = client.Folders.Inbox.Exists;
Greets,

Pavel