Count number of emails in gmail using IMAP
Asked Answered
E

2

9

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)

Eponym answered 22/8, 2010 at 1:8 Comment(1)
Please remove the answer from the question and post it as an actual answer. Thanks!Mcalpine
D
6

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;
Dantzler answered 22/8, 2010 at 1:14 Comment(4)
Could you elaoborate a bit more im completly new to progrsmmingEponym
Thanks for the help worked great so how would i show dis in a labelEponym
Correct me if I'm wrong: you need to reference Mail.dll: lesnikowski.com/mailLindblad
Could you please tell me where you get this Imap class. Is there any .NET library available for Imap?Airdry
E
9

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

Eponym answered 30/8, 2010 at 2:35 Comment(1)
If Url above did not work, it is possible to try to use new version from imapx.codeplex.comGuenzi
D
6

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;
Dantzler answered 22/8, 2010 at 1:14 Comment(4)
Could you elaoborate a bit more im completly new to progrsmmingEponym
Thanks for the help worked great so how would i show dis in a labelEponym
Correct me if I'm wrong: you need to reference Mail.dll: lesnikowski.com/mailLindblad
Could you please tell me where you get this Imap class. Is there any .NET library available for Imap?Airdry

© 2022 - 2024 — McMap. All rights reserved.