1

When I use Python's poplib stat() method to check how many emails there are, it returns 0 even though there are emails in the server. Does anyone know why this happens?

I can connect to the server with my email address and password, but I can't see any emails.

Here's my code:

import poplib

pop_conn = poplib.POP3_SSL("pop.gmail.com")

pop_conn.user("myemail@gmail.com")

pop_conn.pass_("mypassword")

print('Messages: %s. Size: %s' % pop_conn.stat())

pop_conn.quit()

returns: Messages: 0. Size: 0

kalenpw
  • 695
  • 3
  • 10
  • 34
Davies Dan
  • 11
  • 1
  • Have you verified that there are actually messages present? Does `pop_conn.list()` return results that are different from what `.stat` provides? – larsks Feb 09 '21 at 00:00
  • It's 2021. Whatever are you doing using POP3 instead of the now decades old IMAP protocol? – tadman Feb 09 '21 at 01:05
  • 1
    pop_conn.list() returns an empty list, but there are messages present if I log into gmail on a browser. Do they not show up because they've been read? – Davies Dan Feb 09 '21 at 03:17
  • I didn't know about IMAP, I'll research that. Thank you. – Davies Dan Feb 09 '21 at 03:18
  • Try to delete the line "pop_conn.quit()", send new messages and run the code. It worked for me. – Diroallu Dec 02 '22 at 07:51

0 Answers0