
{"id":30,"date":"2021-08-31T16:43:48","date_gmt":"2021-08-31T16:43:48","guid":{"rendered":"http:\/\/pi-smb\/wordpress\/?p=29"},"modified":"2021-08-31T16:43:48","modified_gmt":"2021-08-31T16:43:48","slug":"enable-outgoing-mail-on-raspberry-pi","status":"publish","type":"post","link":"https:\/\/dsslit.ddns.net\/wordpress\/?p=30","title":{"rendered":"Enable Outgoing Mail on Raspberry Pi"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Posted on&nbsp;<a href=\"http:\/\/unixetc.co.uk\/2014\/11\/04\/enable-outgoing-mail-on-raspberry-pi\/\"><time datetime=\"2014-11-04T23:07:05+00:00\">November 4, 2014<\/time><\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This article explains how to send email from the Raspberry Pi. It is a generic procedure and also works on other Debian distributions. This is not for receiving mail, only for sending it. (Receiving email on the Pi is a much more involved process, requiring your Pi to perform the role of a full mail server).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The ability to send mail across the Internet is useful. It enables scripts and applications to send you email about system events or the sending data such as pictures from a webcam.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This article was updated in December 2019 and has been successfully tested on Raspbian Stretch, Jessie and Buster\/Debian 10.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This procedure uses sendmail, the great grandaddy of all email programmes. Install it now as follows. ssh into your pi, or sit in front of the desktop, as you prefer. Become root:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>$&nbsp;<strong>sudo su -<\/strong><\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Update software lists and install:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong># apt-get update\n# apt-get install sendmail libsasl2-modules<\/strong><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This will install sendmail and a few other packages, create the directory \/etc\/mail, and perform a few other tasks. NB the package libsasl2-modules might already be installed (Stertch and Jessie), or not (eg. Buster lite).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Configure Sendmail<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Change to \/etc\/mail and edit the file \/etc\/mail\/<strong>submit.mc<\/strong>, using an editor of your choice. (Do&nbsp;<strong>not<\/strong>&nbsp;edit the submit.cf file)<br><code><br>#&nbsp;<strong>cd \/etc\/mail<\/strong><br>#&nbsp;<strong>vi submit.mc<\/strong><\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Add the three lines shown below in bold to the file. Put them just after the \u201cDOMAIN(`debian-msp\u2019)dnl\u201d line, as shown:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>define(`_USE_ETC_MAIL_')dnl<br>include(`\/usr\/share\/sendmail\/cf\/m4\/cf.m4')dnl<br>VERSIONID(`$Id: submit.mc, v 8.14.4-4 2013-02-11 11:12:33 cowboy Exp $')<br>OSTYPE(`debian')dnl<br>DOMAIN(`debian-msp')dnl<br><strong>define(`SMART_HOST',`[mail.btinternet.com]')dnl<br>FEATURE(`authinfo',`hash -o \/etc\/mail\/authinfo.db')dnl<br>MASQUERADE_AS(`bloggs.gotdns.org')dnl<\/strong><\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here,&nbsp;<strong>mail.btinternet.com<\/strong>&nbsp;is the mail server of my provider (BT). My domain name is&nbsp;<strong>bloggs.gotdns.org<\/strong>. Email sent from the Pi will appear to come from an email address \u201c<strong>&lt;user&gt;@bloggs.gotdns.org<\/strong>\u201c.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Save the&nbsp;<strong>submit.mc<\/strong>&nbsp;file after making the above changes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Next, edit the&nbsp;<strong>authinfo<\/strong>&nbsp;file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>#&nbsp;<strong>vi authinfo<\/strong><\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Make it contain a single line, like this one:<br><code><strong>AuthInfo: \"U:myusername@btinternet.com\" \"P:mypassword\" \"M:PLAIN\"<\/strong><\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>myusername@btinternet.com<\/strong>&nbsp;is my email address at the ISP.&nbsp;<strong>mypassword<\/strong>&nbsp;is the password to go with it. Enter the appropriate address and password for you. Sendmail will use this information to authenticate with your ISP every time it sends an email. It is a basic spam prevention measure implemented by many service providers.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Save the&nbsp;<strong>authinfo<\/strong>&nbsp;file and use&nbsp;<strong>makemap<\/strong>&nbsp;to create the binary version. The following command creates a file called \u201c<strong>authinfo.db<\/strong>\u201c, using the information you placed into&nbsp;<strong>authinfo<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>#&nbsp;<strong>makemap hash \/etc\/mail\/authinfo &lt; \/etc\/mail\/authinfo<\/strong><\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Finally, edit your&nbsp;<strong>\/etc\/hosts<\/strong>&nbsp;file and add your domain to the line containing \u201craspberrypi\u201d. That is the same domain name you used in&nbsp;<strong>submit.mc<\/strong>, above (in my case, bloggs.gotdns.org). On a newly installed Raspbian Jessie, it looks like this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">127.0.1.1       raspberrypi<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Change that to:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">127.0.1.1       raspberrypi bloggs.gotdns.org<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now restart sendmail. This can take a couple of minutes sometimes, so be patient:<br><code>#&nbsp;<strong>service sendmail restart<\/strong><\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong>If you have found this page after encountering a message like \u201c<strong>WARNING: local host name (raspberrypi) is not qualified; see cf\/README: WHO AM I?<\/strong>, then adding the domain name to \/etc\/hosts as just described, should fix it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Send a Test Email<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Send a test email to a mail account you own, eg gmail, hotmail, outlook or whatever:<br><code>#&nbsp;<strong>\/usr\/lib\/sendmail -v someuser@hotmail.com<\/strong><br>Test from Pi<br>&lt;ctrl-d&gt;<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This will print a load of stuff as it sends the mail, including hopefully a \u201c235 PLAIN authentication successful\u201d message. Check your mail account to see the mail came through. (Check the \u201cjunk\u201d mail folder too). It should not take more than a second or two, or maybe a few minutes at very busy times.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Fix Local Email<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If the above test worked, Internet mail is working from your Pi. Great. Now, however, local mail fails. By \u201clocal mail\u201d, I mean email sent from one user on the Pi to another user, for example when&nbsp;<strong>cron<\/strong>&nbsp;sends a user the output from their scheduled jobs, or when the system sends diagnostic messages to the root user. It may not be important to you, but best make it work anyway. Proceed as follows.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Tell sendmail not to authenticate for local mail. Edit the file&nbsp;<strong>\/etc\/mail\/access<\/strong>&nbsp;and add this line:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>SRV_Features:127.0.0.1 A<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Save the file and type \u201cmake\u201d to regenerate its binary version, access.db:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>root@raspberrypi:\/etc\/mail#&nbsp;<strong>vi access<\/strong><br>root@raspberrypi:\/etc\/mail#&nbsp;<strong>make<\/strong><br>Creating \/etc\/mail\/relay-domains<br># Optional file...<br>Updating access_db ...<br>The following file(s) have changed:<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">** ** You should issue `\/etc\/init.d\/sendmail reload` ** **<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Restart sendmail:<br><code>#&nbsp;<strong>service sendmail restart<\/strong><\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you see messages complaining about \u201csasl2-bin\u201d not being installed, and about enabling SASL2 support at a later date, they can be ignored for the purposes of this procedure.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As a test, try sending a local mail. Eg send a mail to the \u201cpi\u201d user.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>root@raspberrypi:\/etc\/mail#&nbsp;<strong>\/usr\/lib\/sendmail -v pi<\/strong><br>Hello pi user from root<br>&lt;ctrl-d&gt;<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Again, lots of diagnostic stuff is printed, indicating successful delivery, including something like \u201c050 \u2026 Sent\u201d.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Check that user pi did indeed receive the mail. We could login as user pi and read the mail with an application (do that by all means), but just tailing the user\u2019s mail file is quicker:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>#&nbsp;<strong>tail \/var\/mail\/pi<\/strong><\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You will see the received mail, ie. lots of header information followed by a blank line and your actual message:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Hello pi user from root<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Raspbian Wheezy only: Enable IPV6<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">At around the end of March 2016, an update was made to Raspbian Wheezy (Debian 7) that will prevent local mail from working unless you have IPv6 enabled. This only affects users of Wheezy. IPv6 is enabled by default on Jessie (Debian 8), so it isn\u2019t a problem. However, Wheezy users might see errors like these after updating their systems with apt-get:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Eg. local mail fails, even after making all of the configurations above:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">root@raspberrypi:# <strong>sendmail -v pi<\/strong>\ntest \npi... Connecting to [127.0.0.1] via relay...\npi... Deferred: Connection refused by [127.0.0.1]<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The \u201cConnection refused\u201d message indicates that the sendmail daemon is not running. Check it with:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">root@raspberrypi:# <strong>ps -ef | grep sendmail<\/strong><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If it isn\u2019t running, attempt to start the daemon:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">root@raspberrypi:# <strong>service sendmail restart<\/strong><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If that falls (check with&nbsp;<strong>ps<\/strong>&nbsp;again), look at the end of the file&nbsp;<strong>\/var\/log\/mail.log<\/strong>&nbsp;for messages like these:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># <strong>tail \/var\/log\/maillog<\/strong>\nroot@raspberrypi:# tail \/var\/log\/mail.log\nApr  3 14:52:07 raspberrypi sm-mta[3064]: NOQUEUE: SYSERR(root): opendaemonsocket: daemon MTA-v6: can't create server SMTP socket: Address family not supported by protocol\nApr  3 14:52:07 raspberrypi sm-mta[3064]: daemon MTA-v6: problem creating SMTP socket\nApr  3 14:52:07 raspberrypi sm-mta[3064]: NOQUEUE: SYSERR(root): opendaemonsocket: daemon MTA-v6: server SMTP socket wedged: exiting<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The sendmail daemon is failing to start because it seems to require IPv6 to be running. After much messing about, I found the easiest solution was just to enable IPv6.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Edit the file \/etc\/modules<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">root@raspberrypi:# <strong>vi \/etc\/modules<\/strong><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">and add a single line to the end of it:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ipv6<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">and reboot the Pi:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">root@raspberrypi:# <strong>shutdown -r 0<\/strong><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">After the system reboots, local mail should be working and sendmail should be running correctly:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">root@raspberrypi:# <strong>sendmail -v pi<\/strong>\ntest\n&lt;ctrl-d&gt; \nroot@raspberrypi:# <strong>ps -ef | grep send<\/strong>\nroot      2381     1  0 00:21 ?        00:00:00 sendmail: MTA: accepting connections \n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Send a Picture<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">It is quite easy to send email attachments from the command line or a script. One of the best ways is to use&nbsp;<strong>mutt<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Install mutt:<br><code>#&nbsp;<strong>apt-get install mutt<\/strong><\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Send an email. You don\u2019t need to be root for this, so type &lt;ctrl-d&gt; to go back to the non-root user. The \u201cecho\u201d bit here just sends an empty email, and the \u201c-a\u201d attaches the jpg file. On my Pi, there is an image called \u201cdriveway.jpg\u201d installed by default. Email it as follows. Note the double minus (\u2013) seperating the destination adddress from the other options:<br><code><br>$&nbsp;<strong>echo | mutt -a \/usr\/share\/scratch\/Media\/Backgrounds\/Outdoors\/driveway.jpg -s \"Photo\" -- someuser@hotmail.com<\/strong><\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I use this method to email webcam pictures to an external email account.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Thanks for reading. I hope you found this guide useful.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Posted on&nbsp;November 4, 2014 This article explains how to send email from the Raspberry Pi. It is a generic procedure and also works on other Debian distributions. This is not for receiving mail, only for sending it. (Receiving email on the Pi is a much more involved process, requiring your Pi to perform the role &hellip; <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,4],"tags":[],"class_list":["post-30","post","type-post","status-publish","format-standard","hentry","category-linux","category-pi"],"_links":{"self":[{"href":"https:\/\/dsslit.ddns.net\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/30","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dsslit.ddns.net\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dsslit.ddns.net\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dsslit.ddns.net\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/dsslit.ddns.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=30"}],"version-history":[{"count":0,"href":"https:\/\/dsslit.ddns.net\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/30\/revisions"}],"wp:attachment":[{"href":"https:\/\/dsslit.ddns.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=30"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dsslit.ddns.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=30"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dsslit.ddns.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=30"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}