0

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.select('INBOX')    

if status != "OK":

        print ("Incorrect mail box")

        exit()

print (messages)
Joe Mayo
  • 7,501
  • 7
  • 41
  • 60
Adam
  • 11
  • 1
  • 2
  • There is an example [in the documentation](https://docs.python.org/3/library/imaplib.html#imap4-example) that seems to do almost exactly what you want. – larsks Jun 16 '18 at 23:23

1 Answers1

7

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"])
ergesto
  • 367
  • 1
  • 8