email package - how to get message body
Rudy Schockaert
Rudy.Schockaert at pandora.be
Mon May 12 07:41:27 EDT 2003
Mario Premke wrote:
> Hi,
> possibly a stupid question, but anyhow, I can not find a method in the
> email package to get an email body ( I mean the text seperated from
> the header by one blank line). I can parse an email file so that I
> have the object model of an email and play around with it (alter
> header properties, etc. ) - what I wonder now is if there is a method
> which returns the simple text message ???
>
> Thans in advance
> Mario
You can use msg.get_payload() where msg is the object representing your
email. Note that things can be more complicated than that depending on
the email message you're about to inspect. Some emails have
multipart/alternative parts each representing the same message but each
time in a different format (text,html, ...)
You can always try the following:
for part in msg.walk():
print part.get_content_type()
to get a list of message parts.
Rudy
More information about the Python-list
mailing list