我正在尝试查看电子邮件的实际正文。到目前为止,我可以查看主题或任何其他标题,但我无法找到一种方法来阅读没有额外内容的正文。
from imapclient import IMAPClient
import email
host = 'imap.gmail.com'
user = 'myEmailAddress'
password = 'myPassword'
ssl = True
server = IMAPClient(host, use_uid=True, ssl=ssl)
server.login(user, password)
inboxInfo = server.select_folder('INBOX')
messages = server.search(['NOT DELETED'])
response = server.fetch(messages, ['RFC822', 'BODY[TEXT]'])
for msgid, data in response.iteritems():
parsedEmail = email.message_from_string(data['RFC822'])
body = email.message_from_string(data['BODY[TEXT]'])
parsedBody = parsedEmail.get_payload(0)
print parsedBody
server.logout()
并返回:
>From nobody Fri Jun 6 01:29:34 2014
>Content-Type: text/plain; charset=UTF-8
>
>Email body
我只想返回:
>Email body