简体   繁体   中英

How to extract email body using the google app engine mail api?

I have an email that looks like this after I extract the body using the mail_message.body() function:

From nobody Sat Mar 29 12:59:23 2014
content-transfer-encoding: 7bit
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"

test name

Is there an easy way to strip the header lines? I just want to extract "test name" and whatever else is after that in the email body. Thank you

Usually the headers are separated with body by two newlines. So you can use this where it is replacing everything before the first two newlines.

body = re.sub("^[\s\S]*?[\n\r][\n\r]", "", body)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM