2
大家好,我使用的脚本包括:1。电子邮件正文文本?
import oauth2 as oauth
import oauth2.clients.imap as imaplib
import email
conn = imaplib.IMAP4_SSL('imap.googlemail.com')
conn.debug = 4
# This is the only thing in the API for impaplib.IMAP4_SSL that has
# changed. You now authenticate with the URL, consumer, and token.
conn.authenticate(url, consumer, token)
# Once authenticated everything from the impalib.IMAP4_SSL class will
# work as per usual without any modification to your code.
conn.select('[Gmail]/All Mail')
response, item_ids = conn.search(None, "SINCE", "01-Jan-2011")
item_ids = item_ids[0].split()
# Now iterate through this shit and retrieve all the email while parsing
# and storing into your whatever db.
for emailid in item_ids:
resp, data = conn.fetch(emailid, "(RFC822)")
email_body = data[0][1]
mail = email.message_from_string(email_body)
我现在的问题是,我似乎无法能够检索mail
实例的身体。我能够通过打印或mail.as_string()来查看电子邮件的内容,但即使使用mail.keys()和mail.values(),我实际上也无法看到邮件的内容(主要消息)。
这封电子邮件lib API有什么问题? (或者说我在做什么错误)?