Привет всем Я использую сценарий, который включает в себя:
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? (точнее что я делаю не так)?