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

Sha*_*121 9 c# gmail imap winforms inbox

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

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

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

收件箱(1)

Sha*_*121 9

解决了

这是我与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;
        }
Run Code Online (Sandbox Code Playgroud)

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

  • 如果上面的Url不起作用,则可以尝试使用http://imapx.codeplex.com上的新版本 (3认同)

qua*_*oup 6

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

Imap imap = new Imap();
/* connect, login, etc. */
imap.Connect(...);
/* fill login and select folder code */

List<long> unseenList = imap.SearchFlag(Flag.Unseen);

// now you can get the count from unseeList
int unread = unseenList.Count;
Run Code Online (Sandbox Code Playgroud)

  • 你能告诉我你在哪里得到这个Imap课程吗?是否有可用于Imap的.NET库? (2认同)