Wednesday, October 30, 2013

Getting the arduino Yun ready to receive and read google mails - part1

I found a lot of examples of how to send mail with the Yun, or how to fetch the google atom feed, but I didn't find any example of how to really receive the full emails with the Yun.

I have a google mail account, so I am focussing only on accessing the google mail (gmail).
Below I will assume my google mail user has the following 'properties':
password:  mypassword

Disclaimer: I have no experience with setting up all this email stuff, so there might be better ways of doing this. What I did is based on a lot of googling.

I asked on the arduino forum for some pointers. I got a suggestion to look into the google python API's, but I got the impression that this is not for free at some point. So I abandoned that route.
I started reading about linux mail 'clients'. I learned a lot of things. I now know more or less what an MTA, MDA, MUA, etc... is :-)

I had no idea if I should use POP3 or IMAP. I went for POP3 for now. So first thing to do is to enable POP3 in your google account (I assume you know how to do this).

Next steps are on the arduino Yun:

login as root and run the following commands:

opkg update
opkg install openssl-util
opkg install fetchmail
opkg install procmail
opkg install shadow-useradd

This installs the packages that I think I will need.

I wasn't sure if I should eventually run my app as root, or if I can do it as another user.
I will give it a try as non-root. I decided to create a user called MrYafa:

mkdir /home 
useradd -m -c "Mr Yafa" MrYafa
passwd MrYafa

Maybe the first command isn't needed. In the last command you obviously need to choose a password.

Then edit the /etc/passwd file   (e.g vi /etc/passwd - I will assume you know how to work with vi)
You should see the newly created user. At the end of that line add /bin/ash

Now exit as root and try to login as MrYafa:

ssh MrYafa@arduino.local

(on windows you might need to enter the IP address as arduino.local might not work)

You should be able to login an arrive in your home directory.


should return


now create a file .fetchmailrc in that directory (vi .fetchmailrc) containing:

with proto pop3
user ""
there with password "mypassword"     
is "MrYafa" here 
mda "/usr/bin/procmail -d %T"

Now, if you give the command

fetchmail -vk

you should see the communication with your google mail on the screen, ending with (in my case):

fetchmail: POP3> QUIT
fetchmail: POP3< +OK Farewell.
fetchmail: 6.3.26 querying (protocol POP3) at Wed, 30 Oct 2013 18:51:33 +0100 (CET): poll completed
fetchmail: normal termination, status 1

One warning is that the connection is insecure. I know that you should use certificates, but haven't figured out yet how to do so. On mu Ubuntu PC I have ca-certificates installed, and there it seems OK. But the ca-certificates package does not seem to be available for Linino. So I need to find another way of making it more secure.

That's it for now. Not so difficult when you know what to do, but it took a while to find that out.

No comments:

Post a Comment