sSMTP is a program which help deliver and email from a linux machine via external email server using SMTP protocol. The program is useful for a machine or server which does not have email server but need to send out an email, such as system notification email.
Installing sSMTP is easy and straightforward by using the command
sudo apt-get install ssmtp -yConfigure SMTP server
After installing, in order to send an email, we’ll need to configure ssmtp.conf file as follows
sudo vim /etc/ssmtp/ssmtp.confSet SMTP to the destination server. Example configuration for sending through Gmail
# Sender email address
root=username@gmail.com
# Destination SMTP server and port
mailhub=smtp.gmail.com:587
# Username and password
AuthUser=username@gmail.com
AuthPass=TYPE-PASSWORD
# Sender domain
rewriteDomain=gmail.com
# Machine's hostname
hostname=localhost
# Allow set From name in each email
FromLineOverride=YESConfig revaliases
Revaliases is use to map local user to form address in outgoing mail. We can config it by edit revaliases config file
sudo vim /etc/ssmtp/revaliasesAnd add the following line
root:username@gmail.com:smtp.gmail.com:587Test sending email
When all the settings are done. We’ll be able to test sending e-mail by using ssmtp command follow by recipient email address:
ssmtp mail_to@domain.comThen we’ll get a blank line, type:
To: mail_to@domain.com
From: username@gmail.com
Subject: This is test email
This is test messageWhen done, press ctrl + d, wait a moment, the system will send a test e-mail to the recipient e-mail.
If all setup is complete, sSMTP will become your default e-mail program for the machine. If other program want to send an email such as notifications. They will be sent through this sSMTP program.