Install SSMTP on Centos 7

| August 31st, 2016

Add the repo if it’s not added:

wget -c https://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-8.noarch.rpm

rpm -ivh epel-release-7-8.noarch.rpm

update:

wget -c https://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-9.noarch.rpm
rpm -ivh epel-release-7-9.noarch.rpm

Install:

yum -y install ssmtp

(yum install mailx) if not installed

Configure:

alternatives --config mta

 

There are 2 programs which provide 'mta'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/sbin/sendmail.postfix
   2           /usr/sbin/sendmail.ssmtp

Enter to keep the current selection[+], or type selection number:

2

 

Disable postfix (or sendmail):

systemctl stop postfix

systemctl disable postfix

Edit SSMTP config file: (/etc/ssmtp/ssmtp.conf)

root=postmaster
mailhub=mail
TLS_CA_File=/etc/pki/tls/certs/ca-bundle.crt
mailhub=smtp.gmail.com:587   # SMTP server for Gmail
Hostname=localhost
UseTLS=YES
UseSTARTTLS=Yes
FromLineOverride=YES #TO CHANGE FROM EMAIL
Root=ROOT@EMAIL # Redirect root email
AuthUser=EMAIL@gmail.com
AuthPass=PASSWORD
AuthMethod=LOGIN
RewriteDomain=gmail.com

 

Test:

echo "TEST EMAIL" | mail -s "SSMTP IS WORKING" TEST@gmail.com

 

 

Probably we’ll get this error:

send-mail: Authorization failed (534 5.7.14  https://support.google.com/mail/answer/78754 r142sm8267633wme.10 – gsmtp)

and Maybe an email to your gmail account with the title: Review blocked sign-in attempt. This is because you have to authorize the App. To do so follow this link: https://support.google.com/accounts/answer/6010255

Update:

Seems there is problem with SSMTP and passwords containing special characters such as “#,$,*…”