0

I want to count the number of emails I have in my GMail inbox using IMAPX. Here is what I have written so far:

if (client.Connect()) {
  Console.WriteLine("Connected Successfully.");
  if (client.Login("MyEmai, "MyPassword")) {
    Folder inbox = client.Folders.Inbox;
    int count = inbox.Messages.Count();
    Console.WriteLine("Total Items:" + count.ToString());
  } 
}

But it is always returning 0 as output. I'm using Version 3.5 of the IMAPX 2.

bruno
  • 2,213
  • 1
  • 19
  • 31
Nitin Singh
  • 159
  • 2
  • 3
  • 14
  • possible duplicate of [Count number of emails in gmail using IMAP](http://stackoverflow.com/questions/3539692/count-number-of-emails-in-gmail-using-imap) – Suji Jul 24 '14 at 11:39
  • possible duplicate : http://stackoverflow.com/questions/3539692/count-number-of-emails-in-gmail-using-imap – Suji Jul 24 '14 at 11:39

1 Answers1

0

By default, the Folder.Messages collection is not being filled. If you want to let the client download the messages automatically, configure the client do do this:

var client = new ImapClient("imap.gmail.com", true);
client.Behavior.AutoPopulateFolderMessages = true;

However, it's often better to make a call to Folder.Messages.Download instead or use Folder.Search

Documentation about message download mode..

Edi G.
  • 2,432
  • 7
  • 24
  • 33
  • 1
    It is not the best way to download all the messages if you just need to get the number of messages in a folder. For this you can use the `Folder.Exists` property. Check my answer to this question on the [official forum](https://imapx.codeplex.com/discussions/553841) – Pavel Azanov Jul 26 '14 at 08:02