See also 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.
apt install ssmtp bsd-mailx
See also 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
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
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.
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
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
cat << EOF >> /tmp/test.eml From: Full Name <validsender@domain.tld> To: Test User <tester@somedomain.tld> Subject: For test only! EOF ssmtp -t < /tmp/test.eml
Debug=YES
tail -30 /var/log/mail.log
On Centos:
alternatives --config mta