如何使用IMAPX 2的3.5版计算我的GMail收件箱中的电子邮件数量

时间:2014-07-24 11:35:40

标签: c# gmail console-application imap

我想使用IMAPX计算我在GMail收件箱中的电子邮件数量。这是我到目前为止所写的内容:

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());
  } 
}

但它总是返回0作为输出。我正在使用IMAPX 2的3.5版。

1 个答案:

答案 0 :(得分:0)

默认情况下,未填充Folder.Messages集合。如果您想让客户端自动下载消息,请配置客户端执行以下操作:

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

但是,调用Folder.Messages.Download或使用Folder.Search

通常会更好。

Documentation about message download mode..