How can I get text of the body (payload) of an email?
M.E.Farmer
mefjr75 at hotmail.com
Sat Oct 16 18:49:05 EDT 2004
"andrew blah" <andrew.stuart at xse.com.au> wrote in message news:<1097890188.684790.103490 at f14g2000cwb.googlegroups.com>...
> I need to get the text of the body (the payload) of an email.
> As I understand it, an email has headers at the top, then a blank line,
> then the body of the message.
> I want to get the text of the body - every character from the new line
> after the headers until the end of the message.
[headers]
[blank line]
[body]
You explained how to do it ;)
> I want to get the text of the body - every character from the new line
> after the headers until the end of the message.
If you just find the first blank line then the next line is the start
of the email body ;)
import poplib
Mail = poplib.POP3('mail.yourserver.net')
Mail.user('username')
Mail.pass_("userpass")
# just get the first message
MyMessage=Mail.retr(1)
FullText=""
PastHeaders=0
for MsgLine in MyMessage[1]:
if PastHeaders==0:
if (len(MsgLine)==0):
PastHeaders = 1
else:
FullText +=MsgLine+'\n'
Mail.quit()
print FullText
This is from Python 2.1 Bible(Dave Brueck,Stephen Tanner);)
That book is an awesome reference still today!
> My objective is to do an SHA hash on the body text so the get_payload
> method isn't what I am after.
> Can anyone suggest a convenient way to get access to the raw message
> payload?
> Thanks in advance for your help.
HTH,
M.E.Farmer :)
More information about the Python-list
mailing list