How to send email from the Beaglebone Black with a Gmail account
Michael Hirsch’s great script checkIP sends an email to you when the IP address of a given computer changes, so you can still ssh into a machine even if Comcast or some other ISP has changed the IP on you (that happens every few months to most residential networks). However there are some problems you’ll run in to if you want to send emails from the command line at a residential address, since Comcast and others block commonly used email ports to prevent spam.
One way around this is to use a Gmail account to send the email for you, while still being able to send it from a Beaglebone. I followed the steps here (and thanks very much to user tcb2 for posting that!) but they need to be altered to work because that post assumes the user has an account with that mailing list. Here are the steps I used to send emails from the Beaglebone Black hooked up at my home:
- Install w3m on the beaglebone so you can visit Google’s authentication website from the command line (unless you have a graphical interface set up for your BBB). Then visit http://www.google.com/accounts/DisplayUnlockCaptcha by typing:
1w3m http://www.google.com/accounts/DisplayUnlockCaptcha
on the command line in your BBB. Enter the email and password you want to use and follow the instructions. Make sure to keep the “stay logged in” box checked. After you’ve done all that, quit out of w3m by typing “q” and answering “y”, then log in to your email on a computer and check google’s message about the recent attempt to log in. Go into your account security settings and confirm that you want that device to be able to access your account. The reason you need to do this is because the BBB will be sending emails on behalf of that account. - Open port 587 on your router and forward it to the BBB.
- Install and configure exim4 as root (exim4 is the program that will send the emails) using:
123sudo apt-get install exim4sudo dpkg-reconfigure exim4-config
In the dialog, answer like so:
Configuration type | mail sent by smarthost; received via SMTP or fetchmail |
System mail name | localhost |
IP-addresses to listen on for incoming SMTP connections | 127.0.0.1 ; ::1 |
Other destinations for which mail is accepted | (leave empty) |
Machines to relay mail for | (leave empty) |
IP address or host name of the outgoing smarthost | smtp.gmail.com::587 |
Hide local mail name in outgoing mail ? | yes |
Keep number of DNS-queries minimal (Dial-on-Demand) ? | no |
Delivery method for local mail | mbox format in /var/mail/ |
Split configuration into small files ? | no |
Then check /etc/exim4/update-exim4.conf.conf and make sure the settings are as shown:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
dc_eximconfig_configtype='smarthost' dc_other_hostnames='' dc_local_interfaces='127.0.0.1 ; ::1' dc_readhost='' dc_relay_domains='' dc_minimaldns='false' dc_relay_nets='' dc_smarthost='smtp.gmail.com::587' CFILEMODE='644' dc_use_split_config='false' dc_hide_mailname='true' dc_mailname_in_oh='true' dc_localdelivery='mail_spool' |
4. Modify /etc/exim4/passwd.client with your own gmail username and password as shown:
1 2 3 4 5 |
gmail-smtp.l.google.com:yourgmailname@gmail.com:yourpassword *.google.com:yourgmailname@gmail.com:yourpassword smtp.gmail.com:yourgmailname@gmail.com:yourpassword |
5. The permissions are probably already set correctly but if not, make sure they’re restricted to root:Debian-exim and only root can read and write to the file (chmod 640).
6. Restart the exim4 daemon:
1 2 3 |
sudo update-exim4.conf sudo invoke-rc.d exim4 restart |
7. All done! Now you can send email from your beaglebone by formatting an ASCII files as follows:
1 2 3 4 5 6 7 8 9 |
to: email@domain.com from: email@domain.com subject: Arbitrary subject goes here! This is the body of my email! |
and sending that file (let’s call it email.txt) with:
1 |
cat email.txt | sendmail -t |
where the -t option causes sendmail to get the needed to: and from: and subject: info from the text file.
Also on an unrelated note, it could substitute for the php mail function thus sending your email securely and depositing a copy of the email in your gmail sent box.
how can i attach files by using this ssmtp mta. i am able to send mails by using ssmtp very comforbly, . plese help how can i do email-attachments with ssmtp?