This is a guide on how to install sSMTP and set it up with Gmail on Ubuntu 16.04.
I installed this to allow CSF/LFD to send email to me, as I didn’t want a full mail server.
Step 1:
Login to SSH as root.
Step 2:
Make sure your Ubuntu Repository, is up to date.
apt-get update
Step 3:
Install sSMTP
apt-get install ssmtp
Step 4:
Configure sSMTP
nano /etc/ssmtp/ssmtp.conf
#
# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
root=MyEmailAddress@gmail.com
# The place where the mail goes. The actual machine name is required no
# MX records are consulted. Commonly mailhosts are named mail.domain.com
mailhub=smtp.gmail.com:587
AuthUser=MyEmailAddress@gmail.com
AuthPass=MyPassword
UseTLS=YES
UseSTARTTLS=YES
# Where will the mail seem to come from?
rewriteDomain=gmail.com
# The full hostname
hostname=localhost
# Are users allowed to set their own From: address?
# YES – Allow the user to specify their own From: address
# NO – Use the system generated From: address
FromLineOverride=YES
Step 5:
Add reverse aliases
nano /etc/ssmtp/revaliases
Add the line:
root:MyEmailAddress@gmail.com:smtp.gmail.com:587
Step 6:
Create a test messae to send
cd /root
nano msg.txt
Add the following lines:
To: MyEmailAddress@gmail.com
From: MyEmailAddress@gmail.com
Subject: test email
Hello World!
Step 7:
Test to make sure it all working
cd /root
/usr/sbin/ssmtp MyEmailAddress@gmail.com < msg.txt
Info:
Be sure to set your Gmail email address where it has:
MyEmailAddress@gmail.com
Remember to set your Password in the ssmtp.conf file.
If you are using Two-Factor you will need to create an App password, instead.