Mohit Ranka
Mohit Ranka

Reputation: 4271

Poplib not working correctly?

I want to get all the messages from my gmail inbox, but I am facing 2 problems.

  1. It does not get all the emails, (as per the count in stat function)
  2. The order of emails it get is random.

I am unsure if its the problem with poplib or gmail pop server.

What am I missing here?

Upvotes: 1

Views: 1428

Answers (4)

Vanuan
Vanuan

Reputation: 33442

It's the problem of gmail: https://mail.google.com/support/bin/answer.py?answer=13291

Try to use recent:[email protected] as your email address. At least you'll have all your last month mail in correct order.

Upvotes: 0

Eugene Morozov
Eugene Morozov

Reputation: 15836

You can also try imaplib module since GMail also provides access to email via IMAP protocol.

Upvotes: 2

Can Berk Güder
Can Berk Güder

Reputation: 113370

What does your code look like? Using poplib, you're able to decide on the order and number of the messages downloaded. The code from the poplib documentation should work:

import getpass, poplib

M = poplib.POP3('localhost')
M.user(getpass.getuser())
M.pass_(getpass.getpass())
numMessages = len(M.list()[1])
for i in range(numMessages):
    for j in M.retr(i+1)[1]:
        print j

Upvotes: 2

Rodrigo
Rodrigo

Reputation: 6038

Why don't you try to use libgmail?

Upvotes: 1

Related Questions