使用IMAP计算Gmail中的电子邮件数量

任何人都可以告诉我如何使用imap或其他东西从我的收件箱中获取未读项目的数量,并将其显示在C#WinForms的标签中?

我尝试使用primefaces进给,但从来没有得到它

这是我想要的样子,如果它有帮助:

收件箱(1)

您可能希望找到设置了UNSEEN标志的所有消息。

 Imap imap = new Imap(); /* connect, login, etc. */ imap.Connect(...); /* fill login and select folder code */ List unseenList = imap.SearchFlag(Flag.Unseen); // now you can get the count from unseeList int unread = unseenList.Count; 

解决了

这是我与ImapX组件一起使用的代码:

  ImapX.ImapClient client = new ImapX.ImapClient("imap.gmail.com", 993, true); bool result = false; result = client.Connection(); if (result) MessageBox.Show("Connection Established"); result = client.LogIn(textBox1.Text, textBox2.Text); if (result) { MessageBox.Show("Logged in"); ImapX.FolderCollection folders = client.Folders; ImapX.MessageCollection messages = client.Folders["INBOX"].Search("UNSEEN", true); //true - means all message parts will be received from server int unread = messages.Count; string unseen = unread.ToString(); button1.Text = unseen; } 

我只需要将int转换为字符串并在按钮中显示字符串(看不见)。 感谢quantumSoup指出我正确的方向