I am trying to make a Python program that only extracts the body of an email message without passing headers or any other parameters. I am not sure how to do this.
The goal is to send basic commands to the program through the message text.
What I have now:
import poplib host = "pop.gmail.com" mail = poplib.POP3_SSL(host) print mail.getwelcome() print mail.user("user") print mail.pass_("pass") print mail.stat() print mail.list() print "" if mail.stat()[1] > 0: print "You have new mail." else: print "No new mail." print "" numMessages = len(mail.list()[1]) for i in range(numMessages): for j in mail.retr(i+1)[1]: print j mail.quit() input("Press any key to continue.")
That everything is fine, except when "print J" is performed, it prints the entire message, including the headers. I just want to extract body text without any extra garbage.
Can anyone help? Thanks!
python email text pop3 poplib
mplewis
source share