Can only get unread emails from Gmail

+1 vote
asked Feb 2, 2011 by Kasper Kirkegaard (170 points)
edited Feb 4, 2011

Hello

I'm evaluating the Secure POP3 for .NET component, and got it working against our Exchange server. When I use Gmail, I can only get the email that arrived since I connected the last time.

According to the mail.google.com site I have 6 unread mails in my inbox, but when I connect with Rebex.Net.Pop3 GetMessageCount and GetMessageList return 0. If I send a new email to Gmail and connect again GetMessageCount and GetMessageList return 1. If I then connect again they return 0.

        Pop3 client = new Pop3();
        Pop3MessageCollection messages;
        MailMessage mail;

        try
        {
            client.Connect(pop3Server, pop3Port, null, Pop3Security.Implicit);
            client.Login(pop3Username, pop3Password);

            if (client.GetMessageCount() > 0)
            {
                messages = client.GetMessageList(Pop3ListFields.Fast);

                foreach (Pop3MessageInfo message in messages)
                {
                    mail = client.GetMailMessage(message.SequenceNumber);

                    foreach (Attachment attachment in mail.Attachments)
                    {
                        attachment.Save(System.IO.Path.Combine(Path, attachment.FileName));
                    }
                }
            }
        }
Applies to: Rebex Secure Mail

3 Answers

0 votes
answered Feb 2, 2011 by Martin Vobr (12,940 points)
edited Feb 2, 2011

Hello,

it looks like your GMail account is configured to sends only fresh messages via POP3 protocol. You might need to reconfigure it. To do so:

  • click on "Settings" link (top, right of the gmail page)
  • click on "Forwarding and POP/IMAP" tab
  • select "Enable POP for all mail (even mail that's already been downloaded)"
  • click "Save changes"

alt text

This should help. Alternatively you can try IMAP for accessing your GMail mailbox. It will enable you to access all your emails and not only messages in the inbox.

commented Feb 3, 2011 by Kasper Kirkegaard (170 points)
POP Download is already set correct. Today I could download all 6 emails when I connected. I then ran the program again and got 0 emails back. When I check in gmail the emails are stil there, and my program do not delete the emails. I have tried with another email component and it always get all the emails.
commented Feb 3, 2011 by Martin Vobr (12,940 points)
Would it be possible to create a communication log as described at http://www.rebex.net/kb/logging.aspx and either include it in your question or send it to support@rebex.net for analysis? It should help us to determine what's going wrong. Also please let me know which other email component are you using so I can try it to and eventually found about the differences.
0 votes
answered Feb 4, 2011 by Kasper Kirkegaard (170 points)
edited Feb 4, 2011

Here is the log. The other component I used was MailBee.NET Objects POP3.

2011-02-04 09:18:29.374 Opening log file.
2011-02-04 09:18:35.639 INFO Pop3(1) Info: Connecting to Pop.gmail.com:995 using Pop3 1.0.3854.0 (trial version).
2011-02-04 09:18:35.732 DEBUG Pop3(1) Info: Connection succeeded.
2011-02-04 09:18:35.740 DEBUG Pop3(1) Info: Upgrading connection to TLS/SSL.
2011-02-04 09:18:35.933 INFO Pop3(1) TLS: State StateChange:Negotiating
2011-02-04 09:18:35.933 DEBUG Pop3(1) TLS: HandshakeMessage:ClientHello was sent.
2011-02-04 09:18:36.007 DEBUG Pop3(1) TLS: HandshakeMessage:ServerHello was received.
2011-02-04 09:18:36.026 DEBUG Pop3(1) TLS: HandshakeMessage:Certificate was received.
2011-02-04 09:18:36.027 DEBUG Pop3(1) TLS: HandshakeMessage:ServerHelloDone was received.
2011-02-04 09:18:36.032 DEBUG Pop3(1) TLS: Verifying server certificate ('C=US, S=California, L=Mountain View, O=Google Inc, CN=pop.gmail.com').
2011-02-04 09:18:36.040 DEBUG Pop3(1) TLS: Certificate verification result: Accept
2011-02-04 09:18:36.048 DEBUG Pop3(1) TLS: HandshakeMessage:ClientKeyExchange was sent.
2011-02-04 09:18:36.059 DEBUG Pop3(1) TLS: CipherSpec:ChangeCipherSpec was sent.
2011-02-04 09:18:36.061 DEBUG Pop3(1) TLS: HandshakeMessage:Finished was sent.
2011-02-04 09:18:36.110 DEBUG Pop3(1) TLS: CipherSpec:ChangeCipherSpec was received.
2011-02-04 09:18:36.111 DEBUG Pop3(1) TLS: HandshakeMessage:Finished was received.
2011-02-04 09:18:36.112 INFO Pop3(1) TLS: State StateChange:Secured
2011-02-04 09:18:36.113 INFO Pop3(1) TLS: Connection secured using cipher: TLS 1.0, RSA, 128bit RC4, MD5
2011-02-04 09:18:36.114 DEBUG Pop3(1) TLS: Session ID: 
    B9-C9-A8-22-F7-A5-DE-C6-60-FC-39-C2-CE-71-8B-13-66-6A-69-95-F1-82-94-0F
    16-6F-8A-B5-B2-16-E5-11
2011-02-04 09:18:36.114 DEBUG Pop3(1) Info: Connection upgraded to TLS/SSL.
2011-02-04 09:18:36.118 INFO Pop3(1) Response: +OK Gpop ready for requests from 91.143.121.3 u43pf4800370wei.2
2011-02-04 09:18:36.122 INFO Pop3(1) Command: CAPA
2011-02-04 09:18:36.168 INFO Pop3(1) Response: +OK Capability list follows
2011-02-04 09:18:37.827 INFO Pop3(1) Command: USER *@*.com
2011-02-04 09:18:38.260 INFO Pop3(1) Response: +OK send PASS
2011-02-04 09:18:38.260 INFO Pop3(1) Command: PASS **********
2011-02-04 09:18:39.620 INFO Pop3(1) Response: +OK Welcome.
2011-02-04 09:18:41.440 INFO Pop3(1) Command: STAT
2011-02-04 09:18:41.632 INFO Pop3(1) Response: +OK 0 0
2011-02-04 09:18:47.156 INFO Pop3(1) Command: QUIT
2011-02-04 09:18:47.597 INFO Pop3(1) Response: +OK Farewell.
2011-02-04 09:18:47.598 DEBUG Pop3(1) TLS: Closing TLS socket.
2011-02-04 09:18:47.599 INFO Pop3(1) TLS: Alert Alert:Alert was sent.
2011-02-04 09:18:47.599 INFO Pop3(1) TLS: State StateChange:Closed
+2 votes
answered Feb 4, 2011 by Jan Sotola (16,930 points)
edited Feb 4, 2011

Hello,

I've verified that both Rebex POP3 and MailBee POP3 components behave the same. When the entire message is downloaded, it won't appear in the message list the next time.

That occurs when using e.g. Rebex GetMailMessage method (or MailBee DownloadEntireMessage method).

Simply:

  • when you retrieve just the message headers from Gmail using POP3, messages are provided again each time you retrieve the message list
  • when you retrieve a message using the GetMailMessage method, the message is marked in Gmail internally as "already received by POP3" and it is not accessible by POP3 connection any more (until the received flag is reset through web settings page).

NOTE: the behavior described only applies if the POP3 session is properly disconnected (by calling Disconnect method on the POP3 instance - calling the Dispose method only is not enough).

Here are two samples (using Rebex and MailBee components) that do the same. Both are retrieving the POP3 messages just one time.

Sample using Rebex Pop3 component:

Pop3 client = new Pop3(); 
client.Connect("pop.gmail.com", Pop3.DefaultImplicitSslPort, null, Pop3Security.Implicit);
client.Login("username", "password");

Pop3MessageCollection messages = client.GetMessageList(Pop3ListFields.FullHeaders); 
foreach (Pop3MessageInfo msg in messages)
{
    // IF THE FOLLOWING LINE IS USED, THE MESSAGE WON'T APPEAR WHEN GETTING THE LIST NEXT TIME 
    // (equivalent to MailBee Pop3.DownloadEntireMessage method)
    MailMessage fullMsg = client.GetMailMessage(msg.SequenceNumber);

    Console.WriteLine("From: " + msg.From + ", To: " + msg.To + ", Subject: " + msg.Subject);
}

client.Disconnect();

Sample using MailBee Pop3 component:

Pop3 pop = new Pop3();
pop.Connect("pop.gmail.com", 995);
pop.SslMode = MailBee.Security.SslStartupMode.OnConnect;
pop.Login("username", "password");

MailMessageCollection msgs = pop.DownloadMessageHeaders();
foreach (MailMessage msg in msgs)
{
    // IF THE FOLLOWING LINE IS USED, THE MESSAGE WON'T APPEAR WHEN GETTING THE LIST NEXT TIME 
    // (equivalent to Rebex Pop3.GetMailMessage method)
    MailMessage fullMsg = pop.DownloadEntireMessage(msg.IndexOnServer);

    Console.WriteLine("From: " + msg.From.Email + ", To: " + msg.To.AsString + ", Subject: " + msg.Subject);                
}

pop.Disconnect();

NOTE: The behavior mentioned in this post is specific for the Gmail POP3 communication. Other POP3 server would behave another way.

commented Feb 4, 2011 by Martin Vobr (12,940 points)
Hmm, what about using IMAP instead of POP3 protocol? It might be solution to your scenario.
...