So I found a this script in another thread. Everything works fine except I cannot get the message "From:", "Date:", and the "Subject:" to show. They show up as NONE.
Below is the code
import imaplib
from email.parser import HeaderParser
myHost = 'imap.gmail.com'
myUsername = 'username'
myPassword = 'password'
m = imaplib.IMAP4_SSL(myHost)
m.login(myUsername,myPassword)
# get list of mailboxes
list = m.list()
# select which mail box to process
m.select("Inbox")
resp, data = m.uid('search',None, "ALL") # search and return Uids
uids = data[0].split()
mailparser = HeaderParser()
for uid in uids:
resp,data = m.uid('fetch',uid,"(BODY[HEADER])")
msg = mailparser.parsestr(str(data[0][1]))
print (msg['From:'],msg['Date:'],msg['Subject:']) # Doesnt Work
print(m.expunge())
m.close() # close the mailbox
m.logout() # logout