Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help with pop3 email read
#1
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:

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())
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help Needed | Read Outlook email Recursively & download attachment Vinci141 1 4,097 Jan-07-2022, 07:38 PM
Last Post: cubangt
  How to read and save specific outlook email into csv Prince_Bhatia 0 7,332 May-03-2018, 05:03 AM
Last Post: Prince_Bhatia
  Read or save email in Outlook 2013 rolan 1 2,959 Apr-06-2018, 09:57 AM
Last Post: Larz60+
  An email with inline jpg cannot be read by all email clients fpiraneo 4 3,994 Feb-25-2018, 07:17 PM
Last Post: fpiraneo
  Email - Send email using Windows Live Mail cyberzen 2 5,932 Apr-13-2017, 03:14 AM
Last Post: cyberzen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020