tags:

views:

639

answers:

1

Using the OpenPOP .net client for getting messages from Gmail.

I'm wondering how I can get only the new messages?

Currently, I get the atom feed and then get as many emails as the feed has with the OpenPOP client (starting from the first).

    GmailAtomFeed feed = new GmailAtomFeed("user", "pass");
    feed.GetFeed();

    int unread = feed.FeedEntries.Count;

    POPClient client = new POPClient("pop.gmail.com", 995, "user", "pass", AuthenticationMethod.USERPASS, true);



    for (int i = 0; i < unread; i++)
    {
        Message m = client.GetMessage(i, false);

        // ...
    }

Is there a better way to do this?

And how do I set the unread messages to be read?

+2  A: 

I doubt you can do it with pop3. From my understanding POP3 doesn't support the notion of the unread\unseen email. It should be up to the client to track messages which were already shown to the user and which were not.

What you can do is switch to using IMAP protocol to access gmail. Check this link for how you can switch it on for your gmail account Getting started with IMAP for Gmail.

Now, if you're using c# there are some commercial libraries for IMAP and there free\opensource ones: like this one on codeproject: IMAP Client library using C#. What you have to do to get unseen messages is to specify "unseen" flag for the select command. Here's an example

serge_gubenko