Oct-13-2018, 08:07 PM
Hello,
I use poplib to read pop3 mail.
I would then like to parse the mail message into <class 'email.message.Message'>
But this fails, the line --> print ('keys in message:',totalMsg.keys())
has no keys in it.
Thanks for your help.
_______________________________
My program:
I use poplib to read pop3 mail.
I would then like to parse the mail message into <class 'email.message.Message'>
But this fails, the line --> print ('keys in message:',totalMsg.keys())
has no keys in it.
Thanks for your help.
_______________________________
My program:
import poplib import email import email.parser import email.policy pop3server="servername" pop3user="username" pop3pass="password" #connect server=poplib.POP3(pop3server) #login server.user(pop3user) server.pass_(pop3pass) resp, items, octets = server.list() numMsg = len(items) parser=email.parser.BytesFeedParser() if numMsg > 0: print ('You have {} new messages'.format(numMsg)) #get first message header,mailmesg,octets=server.retr(1) #convert message to email.message.Message for j in mailmesg: parser.feed(j) else: print ('No new mail') exit() totalMsg=parser.close() #print the message print (totalMsg) print ('keys in message:',totalMsg.keys())