Skip to content Skip to sidebar Skip to footer

I Want To Grab All Emails From An Inbox Using The Python IMAPLIB Module... How Can I Do This?

This is where I am at, but I'm not sure where to go from here: import imaplib import email conn = imaplib.IMAP4() conn.login('username', 'password') status, messages = conn.se

Solution 1:

I have test it under gmx and it works, please take a look at https://docs.python.org/3/library/email.html and https://docs.python.org/3/library/imaplib.html

import imaplib
import email
mail = imaplib.IMAP4_SSL('imap')
mail.login('username', 'password')

status, messages = mail.select('INBOX')    

if status != "OK": exit("Incorrect mail box")

for i in range(1, int(messages[0])):
    res, msg = mail.fetch(str(i), '(RFC822)')
    for response in msg:
        if isinstance(response, tuple):
            msg = email.message_from_bytes(response[1])
            print (msg["subject"])

Post a Comment for "I Want To Grab All Emails From An Inbox Using The Python IMAPLIB Module... How Can I Do This?"