January 22nd 2018

linux, server, mail

Getting email to work with smartd, ssmtp, and picky email providers


My server is running debian jessie.
Recently I had been messing around with different mailing setups, which resulted in total breakage of email sending, as sometimes required by some software, usually via sendmail.

First of all I purged all packages, like dovecot and exim4, and always performed an
"apt-get --purge autoremove" afterwards.
Then I had to go through all the leftover configuration & modifications in /etc. There was a lot of it, even after purging the packages.

With a hopefully clean system, install ssmtp and mailutils: apt-get install ssmtp mailutils.

Configuration for Gmail:

  • activate 'allow less secure apps' from your gmail profile
  • /etc/ssmtp/ssmtp.conf should look like this:

================================

root=someone@gmail.com
mailhub=smtp.gmail.com:587
rewriteDomain=nn.nn.nn.nn (my IP)
hostname=nn.nn.nn.nn
FromLineOverride=YES
UseTLS=YES
UseSTARTTLS=YES
AuthUser=someone@gmail.com
AuthPass=verysecret
AuthMethod=LOGIN

Configuration for other Picky Email Provider

I had to

  • use STARTTLS, and port 587 (instead of 465 for TLS)
  • set up rewriting in both /etc/ssmtp/ssmtp.conf and /etc/ssmtp/revaliases for root and normal user:

==================================

# /etc/ssmtp/ssmtp.conf:
root=mailaddress@posteo.de
normaluser=mailaddress@posteo.de
# /etc/ssmtp/revaliases:
root:mailaddress@posteo.de:smtp.posteo.de:587
username:mailaddress@posteo.de:smtp.posteo.de:587

...maybe that wasn't really necessary, but often it seems to be important that th from addresses matches that of the actual email account used.

Other things

  • Fix permissions on /etc/ssmtp/ssmtp.conf etc. as outlined here (also for /etc/ssmtp/revaliases, see below).
  • I also had to write a custom script for smartd to use ssmtp/sendmail instead of mail. It resides in /usr/share/smartmontools with the other scripts.

Source