2

I have this code:

public List<Attachment> GetAttachments() {
    string hostname = "pop.gmail.com";
    int port = 995;
    bool useSSL = true;
    string attachmentType = "application/pdf";

    string email = "myemail@gmail.com";
    string emailFrom = "someone@gmail.com";
    string password = TxtBoxPassword.Text;

    if (!string.IsNullOrWhiteSpace(password))
    {
        Pop3Client client = new Pop3Client();
        client.Connect(hostname, port, useSSL);
        client.Authenticate(email, password, AuthenticationMethod.UsernameAndPassword);

        List<Attachment> listAttachments = new List<Attachment>();

        int count = client.GetMessageCount();
        for (int i = count; i >= 1; i--)
        {
            Message message = client.GetMessage(i);
            if (message.Headers.From.MailAddress.Address == emailFrom)
            {
                List<MessagePart> attachments = message.FindAllAttachments();
                foreach (MessagePart attachment in attachments)
                {
                    if (attachment.ContentType.MediaType == attachmentType)
                        listAttachments.Add(new Attachment(attachment));
                }
            }
        }
    }
}

To read all emails in email account.

It access the email account and get 265 emails from sent/inbox folders.

Currently I have over thousand emails in the account, so I expect to see this number on count of emails.

What is missing in code/Gmail account settings that is preventing me to get all emails?

Thanks

KleberBH
  • 452
  • 1
  • 9
  • 28
  • 2
    Did you Check "Enable POP for all mail". Go to gmail settings->Forwarding and POP/IMAP->POP Download:->select Enable POP for all mail because by default you will receive only unread messages in gmail pop3. This should resolve your issue. – SGC Jul 09 '15 at 17:25

1 Answers1

0

Well, gmail has some quirks when it gets to it's POP3 features. See my answer on What non-standard behaviour features does Gmail exhibit, when it is programmatically used as a POP3 server?. I do not think you can alter any settings that will remedy your problem.

Community
  • 1
  • 1
foens
  • 8,642
  • 2
  • 36
  • 48
  • 1
    After some research I decided to abandon pop and use IMAP, everything is working perfect now. Thanks a lot – KleberBH Jul 11 '15 at 20:08