====== SSMTP ======
See also **[[networking:linux:postfix_smarthost|Postfix Authenticated Smarthost]]** (Does the same thing without requiring the EPEL repo.)
http://www.linux.com/archive/feature/132006
http://www.squad17.org/node/39
SSMTP is a simple replacement for a full MTA such as Sendmail or Postfix.
* if you already have Postfix installed (RHEL/CentOS), see the link above
* no server daemons
* no running processes
* lightweight
* flexible
* easier than dealing with an MTA
* be sure all you need is a simple outbound sendmail command replacement
===== Installation =====
==== Ubuntu ====
apt install ssmtp bsd-mailx
==== CentOS ====
See also **[[computing:linux:epel|Using the EPEL Repository]]**
Install ssmtp:
yum install ssmtp --enablerepo=epel
On one older system, ''mdadm'' depended on ''sendmail'', I had to do this first:
rpm -e --nodeps sendmail
===== From Address =====
In modern times, secure mail servers are very strict about who is authorized to send mail. You generally must use a **valid sender e-mail 'from address'** that **matches the authentication credentials** used.
Using ''FromLineOverride=YES'' will allow the sender to specify the 'from address' at the time of sending. ''FromLineOverride=NO'' will force the 'from address' to the ''root=validsender@domain.tld'' line in ''ssmtp.conf''.
For sending **system or 'root' mail**, you will probably have to manipulate the 'from address' to get SSMTP to send mail through a secure mail server.
vi /etc/ssmtp/revaliases
root:validsender@domain.tld
===== Configuration =====
For **SSL** connections on **SMTPS port 465**:
vi /etc/ssmtp/ssmtp.conf
root=validsender@domain.tld # will be the 'from address'
mailhub=mail.domain.tld:465 # to use SSL on port 465
RewriteDomain=domain.tld # instead of the host name
#hostname=_HOSTNAME_
#FromLineOverride=YES # allows setting 'from address' at runtime
UseTLS=YES # for SSL
AuthUser=smtpuser
AuthPass=smtppass
#Debug=YES # useful for troubleshooting
:!: If you want to use **TLS** connections on **Submission port 587**, you will need to add/change:
mailhub=mail.domain.tld:587
#UseTLS=YES
UseSTARTTLS=YES
#TLS_CA_File=/etc/pki/tls/certs/ca-bundle.crt # Depends on configuration - Not needed on Ubuntu 18.04
:!: If you don't specify a ''hostname'', SSMTP will query the local machine. Since we are authenticating, the hostname doesn't matter too much.
===== Test =====
:!: If desired, enable (un-comment) the **debug** line, then look in ''/var/log/maillog''.
If desired, install the ''mail'' command:
yum install mailx
update-alternatives --config mta
==== Send a Test Message ====
echo test | mail -s "testing ssmtp" tester@yourdomain.com
Or with no ''mail'' command and no subject line:
echo test | ssmtp -v -f "from@domain.tld" -F "Full Name" tester@yourdomain.com
or
echo test | sendmail -v tester@yourdomain.com
tail -f /var/log/mailog
==== Another Test ====
cat << EOF >> /tmp/test.eml
From: Full Name
To: Test User
Subject: For test only!
EOF
ssmtp -t < /tmp/test.eml
===== Troubleshooting =====
Debug=YES
tail -30 /var/log/mail.log
===== Change the Default MTA =====
On Centos:
alternatives --config mta