Question

I am using poplib in Python 3.3 to fetch emails from a gmail account and everything is working well, except that the mails are not marked as read after retrieving them with the retr() method, despite the fact that the documentation says "Retrieve whole message number which, and set its seen flag."

Here is the code:

pop = poplib.POP3_SSL("pop.gmail.com", "995")
pop.user("recent:mymail@gmail.com")
pop.pass_("mypassword")
numMessages = len(pop.list()[1])
for i in range(numMessages):
    for j in pop.retr(i+1)[1]:
        print(j)
pop.quit()

Am I doing something wrong or does the documentation lie? (or, did I just misinterpret it?)

Was it helpful?

Solution

The POP protocol has no concept of "read" or "unread" messages; the LIST command simply shows all existing messages. You may want to use another protocol, like IMAP, if the server supports it.

You could delete messages after successful retrieval, using the DELE command. Only after a successful QUIT command will the server actually delete them.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top