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

发布于 2024-09-15 14:39:50 字数 136 浏览 6 评论 0原文

谁能告诉我如何使用 imap 或其他东西从 gmail 获取收件箱中未读邮件的数量,并将其显示在 C# WinForms 的标签中?

我尝试使用原子提要,但永远无法得到它

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

Can anyone tell me how I can get the number of unread items in my inbox from gmail using imap or something else and display it in a label in C# WinForms?

I tried using atom feeds, but never could get it

Here is what I want to look like, if it helps:

Inbox(1)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

無心 2024-09-22 14:39:50

已解决

这是我与 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为我指明了正确的方向

SOLVED

Here is the code i used with the ImapX component:

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

i just had to covert the int to a string and show the string (unseen) in the button. Thanks to quantumSoup for pointing me in the right direction

汹涌人海 2024-09-22 14:39:50

您可能想要查找设置了 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;

You probably want to find all messages with the UNSEEN flag set.

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文