Getting email off your Linux server with ssmtp and yandex

A quick note to self about configuration of servers with ssmtp and yandex mail service (any other would work too, of course). I keep forgetting how it is done and keep spending time looking about so here goes the summary.

Install ssmtp package, if missing, install also bsd-mailx.

Configuration for ssmtp goes into /etc/ssmtp/ssmtp.conf # Provider SMTP server hostname and port
UseStartTLS=YES # Secure connection (SSL/TLS)
FromLineOverride=YES # Force the From: line # The name of this host # The host the mail appears to be coming from # Redirect mail for root@ to # Provider mail account
AuthPass=password # The password for the mail account

Note that it is not UseTLS anymore but UseStartTLS, otherwise you’ll get

May 25 18:47:18 example sSMTP[315]: Creating SSL connection to host
May 25 18:47:18 example sSMTP[315]: SSL connection using (null)
May 25 18:47:18 example sSMTP[315]: Cannot open

Now all of the accounts that send email must be mentioned in the /etc/ssmtp/revaliases file and be mapped to this existing account at the provider:

Now we have a working configuration but the password for the service is exposed in a world-readable config file. To fix that, we create a new group:

groupadd ssmtp

Change the ownership of both the config file and the sSMTP binary to this group:

chown :ssmtp /etc/ssmtp/ssmtp.conf

chown :ssmtp /usr/sbin/ssmtp

Set the SGID bit for the binary so that others invoking it get the proper permissions:

chmod g+s /usr/sbin/ssmtp

And restrict the permissions of the config file:

chmod 640 /etc/ssmtp/ssmtp.conf

Now everything should work like a charm… unless I forgot something again :)… -->

continue reading →