Reputation: 39
I am trying to receive emails on my Pi, so far I am receiving the emails from my inbox from gmail however I am trying to receive them without all the added content such as the message ID and content type. Im looking for pure email body text. I've got this so far....
import imaplib
mail = imaplib.IMAP4_SSL('imap.gmail.com')
mail.login('xxxxxxx', 'xxxxxx')
mail.list
mail.select("inbox")
obj, data = mail.search(None, 'ALL')
for num in data [0].split():
typ, data = mail.fetch(num, '(RFC822)')
print 'Message %s\n%s\n' % (num, data[0][1])
mail.close()
Upvotes: 2
Views: 971
Reputation: 39
So I made the rookie mistake of naming my file email.py and also not importing email!
Thank you.
Upvotes: 0
Reputation: 164
Try passing 'BODY[1]'
as the string as opposed to '(RFC822)'
.
What 'BODY[1]'
does is that it specifies that you only want the text/plain portion of the email. You can find inside this document RFC 3501, which explains in detail FETCH commands under section 6.4.5, or page 53.
Hope this helps!
Upvotes: 1