{"id":2910,"date":"2017-05-29T00:00:15","date_gmt":"2017-05-29T07:00:15","guid":{"rendered":"http:\/\/192.168.3.4\/?p=2910"},"modified":"2018-01-09T06:51:26","modified_gmt":"2018-01-09T14:51:26","slug":"cli-email-using-blat-and-ssmtp","status":"publish","type":"post","link":"https:\/\/www.cloudacm.com\/?p=2910","title":{"rendered":"CLI email using Blat and SSMTP"},"content":{"rendered":"<p>When you are away from your computer, how do you know it is operating as expected?\u00a0 Some might use a web front end to allow them a way to periodically check it, but that involves taking a few moments to do.\u00a0 Instead of the person initiating the check, how about having the machine initiate its status.\u00a0 One way to do this is using email as the transport method.<\/p>\n<p>In this post I&#8217;ll cover two command line email tools that will send email from the command line.\u00a0 The first is Blat, which runs on Windows based computers.\u00a0 The next is SSMTP, which runs on Linux based computers.\u00a0 These tools are simple to use, but require some up front work to get them to operate as expected.<\/p>\n<p>First you&#8217;ll want to get your email host account settings.\u00a0 This information is what you use to setup email on clients like Outlook, Thunderbird, or your smart phone.\u00a0 Some email hosts have help pages that provide those details, refer to your provider, I will not provide that here.<\/p>\n<p>Now you should have things like.<\/p>\n<ul>\n<li>User login<\/li>\n<li>Password<\/li>\n<li>SMTP server<\/li>\n<li>SMTP port<\/li>\n<li>Encyrption<\/li>\n<\/ul>\n<p>We&#8217;ll need that when we use Blat or SSMTP.\u00a0 Let&#8217;s start with SSMTP.\u00a0 If you haven&#8217;t already, install it using this command.<\/p>\n<p>sudo apt-get install mutt ssmtp mailutils<\/p>\n<p>I&#8217;ve added Mutt and Mailutils becuase I also want additional functionality that I won&#8217;t cover here, that will be for future posts.\u00a0 You can leave them out if you prefer, but you&#8217;ll need them later if you plan to follow me later.<\/p>\n<p>Next, I make a backup of my SSMTP configuration using this command.<\/p>\n<p>cp \/etc\/ssmtp\/ssmtp.conf \/etc\/ssmtp\/ssmtp.conf.bak<\/p>\n<p>Now I&#8217;m ready to edit my config file so that my email providers settings are correct.\u00a0 Here is an example<\/p>\n<p>root=admin@email.com<br \/>\nmailhub=smtp.email.com:port<br \/>\nAuthMethod=LOGIN<br \/>\nAuthUser=admin@email.com<br \/>\nAuthPass=password<br \/>\nUseTLS=YES\/NO<br \/>\nUseSTARTTLS=YES\/NO<br \/>\nFromLineOverride=YES\/NO<\/p>\n<p>Next we&#8217;ll edit our reverse aliases so that we have the correct senders email.<\/p>\n<p>sudo nano \/etc\/ssmtp\/revaliases<\/p>\n<p>Here is an example that follows my format above.<\/p>\n<p>root:admin@email.com:smtp.email.com:port<\/p>\n<p>Before we go further let&#8217;s talk about security, because your email password is stored as cleartext in \/etc\/ssmtp\/ssmtp.conf.\u00a0 It is important to secure that file.\u00a0 Refer to this site for details or search for &#8220;Secure ssmtp.conf&#8221;<\/p>\n<p>https:\/\/wiki.archlinux.org\/index.php\/SSMTP<\/p>\n<p>Now you should be ready to send a message with SSMTP.\u00a0 Type the following command in the terminal, replace the email address below with yours.<\/p>\n<p>du -sh | mail -s &#8220;disk usage&#8221; admin@email.com<\/p>\n<p>If all is working, you should see a message with the subject &#8220;disk usage&#8221;.\u00a0 If you hadn&#8217;t noticed, I&#8217;m piping a standard output from the terminal into the body of my email.\u00a0 This is a useful tool indeed.<\/p>\n<p>For Windows machines, we&#8217;ll use Blat.\u00a0 It can be downloaded from http:\/\/www.blat.net.<\/p>\n<p>Once downloaded, to use the settings for your account, use this command in a command prompt.\u00a0 Be sure your path to the blat executable works.<\/p>\n<p>blat -server (FQDN or IP of your mail server) -port (TCP port of your mail server) -u (Your email account name) -pw (Your email account password) -subject &#8220;This is the subject of your email&#8221; -body &#8220;This is the text inside the body of your email message.&#8221; -attach (This Is Your Attached File.txt) -to (This is who you are sending it to) -f (This is who you are saying it is from)<\/p>\n<p>That should cover the basics of command line email.\u00a0 If you have automated scripts or other process that run, having a way to notify the status is useful when you&#8217;re away from your computer.\u00a0 In addition, it is a remote logging function.\u00a0 It can be useful to have a paper trail.<\/p>\n<p>I hope you have found this information useful and look forward to stepping away the system admin stuff for awhile.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When you are away from your computer, how do you know it is operating as expected?\u00a0 Some might use a web front end to allow them a way to periodically check it, but that involves taking a few moments to do.\u00a0 Instead of the person initiating the check, how about having the machine initiate its status.\u00a0 One way to do this is using email as the transport method. In this post I&#8217;ll cover two command line email tools that will&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/www.cloudacm.com\/?p=2910\"> 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-2910","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\/2910","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=2910"}],"version-history":[{"count":5,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts\/2910\/revisions"}],"predecessor-version":[{"id":2915,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts\/2910\/revisions\/2915"}],"wp:attachment":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2910"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2910"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2910"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}