read email, including body

Hi,

I see many Yun, cUrl, Temboo examples that allow sending email, or reading the atom feed to get e.g. the headers of new email.

But I want to do is actually read the whole email, including the body of the mail. Can someone point me in the right direction?

It is a google mail that I want to access.

Thanks,

Nico

Try this.

First link leads to anything but gmail. Second link is all about gmail

Thanks, I hadn't been looking into the direction of python. I will have a look !

I'm sure it's not the only way, but having python already installed on the yun, it sure is the easiest

The issue with the google app API seems that it is not free above a certain usage. And the limit seems to be very low, e.g. 100 calls per day. I assume checking mail counts as 1, so you can only check your mail 100 times a day. This is from a first reading, maybe I missed something. I didnt look at the other links(s) yet.

I think I will also have a look if there are no useable mail clients that I can use on the linux. I saw mutt and fetchmail can be installed via the package manager.

Just as a follow-up, I managed to receive and read complete emails (so not only the headers) using fetchmail (over ssl) and procmail.

NewLine, I did never get fetcmail to work, do you mind sharing what you did ?

I used atyhis python script instead, I didn't need to install extra modules to get it working It reads the last mail from the mailfolder Inbox

Most of the code I got here: http://yuji.wordpress.com/2011/06/22/python-imaplib-imap-example-with-gmail/

import imaplib
import email

mail = imaplib.IMAP4_SSL('imap.xxx.com')
mail.login('xxxx@xxxx.dk', 'xxxxxx')
mail.list()
# Out: list of "folders" aka labels in gmail.
mail.select("inbox") # connect to inbox.

result, data = mail.search(None, "ALL")

ids = data[0] # data is a list.
id_list = ids.split() # ids is a space separated string
latest_email_id = id_list[-1] # get the latest

result, data = mail.fetch(latest_email_id, "(RFC822)") # fetch the email body (RFC822) for the given ID

raw_email = data[0][1] # here's the body, which is raw text of the whole email
# including headers and alternate payloads
print result
#print raw_email
email_message = email.message_from_string(raw_email)

print email_message['To']
print email_message['From']
print email_message['Subject']

#print the body

if email_message.is_multipart():
    for part in email_message.get_payload():
        print part.get_payload()
else:
    print email_message.get_payload()

Erni, I am keeping a blog of my progress. It is initially mainly written for myself so that I can remember what I did. You can find the blog at http://myyafa.blogspot.be/

Your python code is also interesting, and maybe even simpler.