KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I would like to receive email using python. So far I have been able to get the subject but not the body. Here is the code I have been using: import poplib from email import parser pop_conn = poplib.POP3_SSL('pop.gmail.com') pop_conn.user('myusername') pop_conn.pass_('mypassword') #Get messages from server: messages = [pop_conn.retr(i) for i in range(1, len(pop_conn.list()[1]) + 1)] # Concat message pieces: messages = ["\n".join(mssg[1]) for mssg in messages] #Parse message intom an email object: messages = [parser.Parser().parsestr(mssg) for mssg in messages] for message in messages: print message['subject'] print message['body'] pop_conn.quit() My issue is that when I run this code it properly returns the Subject but not the body. So if I send an email with the subject "Tester" and the body "This is a test message" it looks like this in IDLE. >>>>Tester >>>>None So it appears to be accurately assessing the subject but not the body, I think it is in the parsing method right? The issue is that I don't know enough about these libraries to figure out how to change it so that it returns both a subject and a body.
Tags (comma-separated)
Save Edits
Cancel