0

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 
BigEfromDaBX
  • 157
  • 1
  • 2
  • 10
  • IIRC, you're supposed to access these without the colon (:). I.e., `msg['From'],msg['Date'],msg['Subject']`. –  Nov 20 '19 at 04:12
  • @JustinEzequiel That didnt work. It returned. ``` None None None None None None None None None ('OK', [None]) ``` – BigEfromDaBX Nov 21 '19 at 06:34

0 Answers0