{"id":40,"date":"2015-05-28T16:04:09","date_gmt":"2015-05-28T20:04:09","guid":{"rendered":"http:\/\/knek-tek.me\/?p=40"},"modified":"2015-06-02T15:03:20","modified_gmt":"2015-06-02T19:03:20","slug":"how-to-send-email-from-the-beaglebone-black-with-a-gmail-account","status":"publish","type":"post","link":"http:\/\/knek-tek.me\/index.php\/2015\/05\/28\/how-to-send-email-from-the-beaglebone-black-with-a-gmail-account\/","title":{"rendered":"How to send email from the Beaglebone Black with a Gmail account"},"content":{"rendered":"<p>Michael Hirsch&#8217;s great script <a href=\"https:\/\/github.com\/scienceopen\/pybashutils\/blob\/master\/checkIP.sh\" target=\"_blank\">checkIP<\/a> 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&#8217;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.<\/p>\n<p>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 <a href=\"http:\/\/comments.gmane.org\/gmane.comp.hardware.beagleboard.user\/82032\" target=\"_blank\">here<\/a> (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:<\/p>\n<ol>\n<li><a href=\"http:\/\/www.howtogeek.com\/103574\/how-to-browse-from-the-linux-terminal-with-w3m\/\" target=\"_blank\">Install w3m<\/a> on the beaglebone so you can visit Google&#8217;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:\n<pre class=\"lang:default highlight:0 decode:true\">w3m http:\/\/www.google.com\/accounts\/DisplayUnlockCaptcha<\/pre>\n<p>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 &#8220;stay logged in&#8221; box checked. After you&#8217;ve done all that, quit out of w3m by typing &#8220;q&#8221; and answering &#8220;y&#8221;, then log in to your email on a computer and check google&#8217;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.<\/li>\n<li>Open port 587 on your router and forward it to the BBB.<\/li>\n<li>Install and configure exim4 as root (exim4 is the program that will send the emails) using:\n<pre class=\"lang:sh highlight:0 decode:true\">sudo apt-get install exim4\r\nsudo dpkg-reconfigure exim4-config<\/pre>\n<p>In the dialog, answer like so:<\/li>\n<\/ol>\n<table border=\"1\">\n<tbody>\n<tr>\n<td>Configuration type<\/td>\n<td>\u00a0mail sent by smarthost; received via SMTP or fetchmail<\/td>\n<\/tr>\n<tr>\n<td>\u00a0System mail name<\/td>\n<td>\u00a0localhost<\/td>\n<\/tr>\n<tr>\n<td>\u00a0IP-addresses to listen on for incoming SMTP connections<\/td>\n<td>\u00a0127.0.0.1 ; ::1<\/td>\n<\/tr>\n<tr>\n<td>Other destinations for which mail is accepted<\/td>\n<td>(leave empty)<\/td>\n<\/tr>\n<tr>\n<td>Machines to relay mail for<\/td>\n<td>(leave empty)<\/td>\n<\/tr>\n<tr>\n<td>IP address or host name of the outgoing smarthost<\/td>\n<td>smtp.gmail.com::587<\/td>\n<\/tr>\n<tr>\n<td>Hide local mail name in outgoing mail ?<\/td>\n<td>yes<\/td>\n<\/tr>\n<tr>\n<td>Keep number of DNS-queries minimal (Dial-on-Demand) ?<\/td>\n<td>no<\/td>\n<\/tr>\n<tr>\n<td>Delivery method for local mail<\/td>\n<td>mbox format in \/var\/mail\/<\/td>\n<\/tr>\n<tr>\n<td>Split configuration into small files ?<\/td>\n<td>no<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Then check \/etc\/exim4\/update-exim4.conf.conf and make sure the settings are as shown:<\/p>\n<pre class=\"lang:default highlight:0 decode:true\">dc_eximconfig_configtype='smarthost'\r\ndc_other_hostnames=''\r\ndc_local_interfaces='127.0.0.1 ; ::1'\r\ndc_readhost=''\r\ndc_relay_domains=''\r\ndc_minimaldns='false'\r\ndc_relay_nets=''\r\ndc_smarthost='smtp.gmail.com::587'\r\nCFILEMODE='644'\r\ndc_use_split_config='false'\r\ndc_hide_mailname='true'\r\ndc_mailname_in_oh='true'\r\ndc_localdelivery='mail_spool'\r\n<\/pre>\n<p>4. Modify \/etc\/exim4\/passwd.client with your own gmail username and password as shown:<\/p>\n<pre class=\"lang:default highlight:0 decode:true\">gmail-smtp.l.google.com:yourgmailname@gmail.com:yourpassword \r\n*.google.com:yourgmailname@gmail.com:yourpassword \r\nsmtp.gmail.com:yourgmailname@gmail.com:yourpassword<\/pre>\n<p>5. The permissions are probably already set correctly but if not, make sure they&#8217;re restricted to root:Debian-exim and only root can read and write to the file (chmod 640).<\/p>\n<p>6. Restart the exim4 daemon:<\/p>\n<pre class=\"lang:default highlight:0 decode:true\">sudo update-exim4.conf\r\nsudo invoke-rc.d exim4 restart<\/pre>\n<p>7. All done! Now you can send email from your beaglebone by formatting an ASCII files as follows:<\/p>\n<pre class=\"lang:default highlight:0 decode:true\" title=\"email.txt\">to: email@domain.com\r\nfrom: email@domain.com\r\nsubject: Arbitrary subject goes here!\r\n\r\nThis is the body of my email!\r\n<\/pre>\n<p>and sending that file (let&#8217;s call it email.txt) with:<\/p>\n<pre class=\"lang:default highlight:0 decode:true \">cat email.txt | sendmail -t<\/pre>\n<p>where the -t option causes sendmail to get the needed to: and from: and subject: info from the text file.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Michael Hirsch&#8217;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&#8217;ll <a class=\"read-more\" href=\"http:\/\/knek-tek.me\/index.php\/2015\/05\/28\/how-to-send-email-from-the-beaglebone-black-with-a-gmail-account\/\">Continue Reading<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,21,27,20,19],"tags":[],"class_list":["post-40","post","type-post","status-publish","format-standard","hentry","category-bash","category-beaglebone","category-email","category-internet","category-web"],"_links":{"self":[{"href":"http:\/\/knek-tek.me\/index.php\/wp-json\/wp\/v2\/posts\/40","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/knek-tek.me\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/knek-tek.me\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/knek-tek.me\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/knek-tek.me\/index.php\/wp-json\/wp\/v2\/comments?post=40"}],"version-history":[{"count":10,"href":"http:\/\/knek-tek.me\/index.php\/wp-json\/wp\/v2\/posts\/40\/revisions"}],"predecessor-version":[{"id":79,"href":"http:\/\/knek-tek.me\/index.php\/wp-json\/wp\/v2\/posts\/40\/revisions\/79"}],"wp:attachment":[{"href":"http:\/\/knek-tek.me\/index.php\/wp-json\/wp\/v2\/media?parent=40"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/knek-tek.me\/index.php\/wp-json\/wp\/v2\/categories?post=40"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/knek-tek.me\/index.php\/wp-json\/wp\/v2\/tags?post=40"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}