{"id":1634,"date":"2014-12-23T00:00:33","date_gmt":"2014-12-23T08:00:33","guid":{"rendered":"http:\/\/192.168.3.4\/?p=1634"},"modified":"2018-01-09T06:49:50","modified_gmt":"2018-01-09T14:49:50","slug":"rpi-email-using-ssmtp","status":"publish","type":"post","link":"https:\/\/www.cloudacm.com\/?p=1634","title":{"rendered":"RPi email using sSMTP"},"content":{"rendered":"<p><strong>Introduction &#8211; There has got to be an easier way.<\/strong><\/p>\n<p>After setting up Cacti and automating tasks with CRON and Webmin, email notification was the next step. \u00a0Searches for sending email from Linux typically generate results that gravitate\u00a0around sendmail. \u00a0This is no different for the RPi. \u00a0Sendmail has its good points, but its a service that runs constantly and provides features well beyond simple email notification.<\/p>\n<p>I wanted a binary that just sends emails and only runs when I need it. \u00a0This was the reason for sSMTP.<\/p>\n<p><strong>Purpose &#8211; When a guide isn&#8217;t all that clear<\/strong><\/p>\n<p>My initial findings looked promising. \u00a0All I had to do was follow a few steps; install, config, and run. \u00a0The problem I ran into was the config portion. \u00a0None of the well formatted posts I viewed gave the correct steps and this led to my trouble. \u00a0So as a result, I decided to take time during my Winter break and do this write up.<\/p>\n<p><strong>Details &#8211; When you want it done right&#8230;<\/strong><\/p>\n<p>The first step is to open a command shell on the RPi and check for updates.<\/p>\n<pre>\r\n<code>\r\nsudo apt-get update\r\n<\/code>\r\n<\/pre>\n<p>If you have any install them first, reboot as needed.<\/p>\n<pre>\r\n<code>\r\nsudo apt-get upgrade\r\n<\/code>\r\n<\/pre>\n<p>Next up, you&#8217;ll want to install the sSMTP binaries, super easy so far.<\/p>\n<pre>\r\n<code>\r\nsudo apt-get install ssmtp\r\n<\/code>\r\n<\/pre>\n<p>Now that this is done, open the config file and edit it for your system.<\/p>\n<pre>\r\n<code>\r\nsudo nano\u00a0\/etc\/ssmtp\/ssmtp.conf\r\n<\/code>\r\n<\/pre>\n<p>This will open up the file and give you areas to edit so they work with your email host. \u00a0The system below uses encryption in the authentication, so the mailhub has a port number (587) tagged on the end with a colon (:).<\/p>\n<pre>\r\n<code>\r\n==========(SOF)=================================================\r\n#\r\n# Config file for sSMTP sendmail\r\n#\r\n# The person who gets all mail for userids &lt; 1000\r\n# Make this empty to disable rewriting.\r\nroot=<strong>********@yourdomain.com<\/strong>\r\n\r\n# The place where the mail goes. The actual machine name is required no\r\n# MX records are consulted. Commonly mailhosts are named mail.domain.com\r\nmailhub=<strong>**************.yourdomain:587<\/strong>\r\nAuthMethod=<strong>LOGIN<\/strong>\r\nAuthUser=<strong>********@yourdomain.com<\/strong>\r\nAuthPass=<strong>**********<\/strong>\r\nUseSTARTTLS=<strong>YES<\/strong>\r\n\r\n# Where will the mail seem to come from?\r\nrewriteDomain=\r\n\r\n# The full hostname\r\nhostname=<strong>rpi.yourdomain.com<\/strong>\r\n\r\n# Are users allowed to set their own From: address?\r\n# YES - Allow the user to specify their own From: address\r\n# NO - Use the system generated From: address\r\nFromLineOverride=<strong>YES<\/strong>\r\n\r\n=================================================(EOF)==========\r\n<\/code>\r\n<\/pre>\n<p>With the proper formatting out of the way, you should be able to run a test script using a text file as your message header and body. \u00a0Create a text file in nano and enter in the info that pertains to you.<\/p>\n<pre>\r\n<code>\r\n==========(SOF)=================================================\r\n\r\nTo: ********@yourdomain.com\r\nFrom: ********@yourdomain.com\r\nSubject: Scripted Message\r\n\r\nThis is a scripted message to check if ssmtp will work from the RPi.\r\n\r\n=================================================(EOF)==========\r\n<\/code>\r\n<\/pre>\n<p>Now with the text file all set, you can run the script from the command prompt.<\/p>\n<pre>\r\n<code>\r\nssmtp ********@yourdomain.com &lt;\/home\/user\/msg.txt\r\n<\/code>\r\n<\/pre>\n<p>After a few moments, you should or someone else, will have the email message in the inbox. \u00a0If you have trouble, Webmin is here to help. \u00a0In the System section, click System Logs and choose the \/var\/log\/mail.log log to view. This helped me narrow down why the earlier posts didn&#8217;t cut it for me. I&#8217;m not without fault, so this might help you find why I didn&#8217;t cut it.<\/p>\n<p><strong>Relations &#8211; Automated notification.<\/strong><\/p>\n<p>Now that the business of emailing from RPi is out of the way, you can go about setting up notifications. \u00a0These can be scheduled with CRON scripts, or scripts that are called by other processes, such as Cacti. \u00a0Cacti has some marvelous plugins that would be drab without the email function. \u00a0This step is key to allowing that to work.<\/p>\n<p><strong>Summary &#8211; Now you get the message.<\/strong><\/p>\n<p>The task of email notification should be kept as simple as possible when dealing with the RPi. \u00a0For that, I showed how to install, setup, and use sSMTP as that notification tool. \u00a0The setup requires attention to the proper entries in the config file. \u00a0I also covered how to debug, should any unexpected problems arise. \u00a0Once the initial setup and config work was done, I then stepped through how to send a message from the command line. \u00a0We then went into more details of potential use for sSMTP with Cacti.<\/p>\n<p>The sites that I had found useful are listed here; these were instrumental in my success with sSMTP:<\/p>\n<p><a href=\"https:\/\/wiki.debian.org\/sSMTP\" target=\"_blank\">https:\/\/wiki.debian.org\/sSMTP<\/a><br \/>\n<a href=\"http:\/\/www.havetheknowhow.com\/Configure-the-server\/Install-ssmtp.html\" target=\"_blank\">http:\/\/www.havetheknowhow.com\/Configure-the-server\/Install-ssmtp.html<\/a><br \/>\n<a href=\"http:\/\/forums.gentoo.org\/viewtopic-t-439502-start-0.html\" target=\"_blank\">http:\/\/forums.gentoo.org\/viewtopic-t-439502-start-0.html<\/a><\/p>\n<p><a href=\"http:\/\/theoatmeal.com\/comics\/semicolon\" target=\"_blank\">http:\/\/theoatmeal.com\/comics\/semicolon<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction &#8211; There has got to be an easier way. After setting up Cacti and automating tasks with CRON and Webmin, email notification was the next step. \u00a0Searches for sending email from Linux typically generate results that gravitate\u00a0around sendmail. \u00a0This is no different for the RPi. \u00a0Sendmail has its good points, but its a service that runs constantly and provides features well beyond simple email notification. I wanted a binary that just sends emails and only runs when I need&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/www.cloudacm.com\/?p=1634\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,3],"tags":[],"class_list":["post-1634","post","type-post","status-publish","format-standard","hentry","category-raspberry-pi","category-rd"],"_links":{"self":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts\/1634","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1634"}],"version-history":[{"count":16,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts\/1634\/revisions"}],"predecessor-version":[{"id":1912,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts\/1634\/revisions\/1912"}],"wp:attachment":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1634"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1634"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1634"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}