email package - how to get message body

Norbert Klamann Norbert.Klamann at klamann-software.de
Mon May 12 09:18:59 EDT 2003


Mario.Premke at epost.de (Mario Premke) wrote in message news:<e1c1191c.0305120231.1bc272b8 at posting.google.com>...
> 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 ???

because there can be several parts in an email, this body is not _that_ simple.


something like this should help you get further :

    for part in msg.walk():
        typ = part.get_type()
        if typ and typ.lower() == "text/plain":
            # Found the first text/plain part
            body = part.get_payload(decode=True)
            break

> 
> Thans in advance  
> Mario

HTH

Norbert




More information about the Python-list mailing list