import imaplib import time # Put your credentials here... hostname = 'imap.example.com' username = 'j.doe' password = 'password' imaplib.Debug = 3 connection = imaplib.IMAP4_SSL(hostname) connection.login(username, password) connection.select('Inbox') time.sleep(30) # With another IMAP client open, say, Thunderbird. # Send a few emails to the account. # (Might require a longer delay if emailing across domains) # This will provide noop() with some untagged responses. connection.noop() # Crashes here. # If the code gets here then noop() has not found any untagged responses. connection.close() connection.logout()