Send email alerts using ssmtp

Here’s how to setup sending emails through command line. A common application could be to send an alert message through user created script.


  • Ubuntu Server/Desktop
  • Gmail account


Update Ubuntu Repository

sudo apt-get update

Install the ssmtp package

sudo apt-get install ssmtp

configure ssmtp

Edit the configuration file. The lines without the # are the ones we are interested in.

sudo nano /etc/ssmtp/ssmtp.conf

Adjust and add as necessary to match the following parameters

Change "MyEmailAddress" and "MyPassword" to your own.

# Config file for sSMTP sendmail
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.

# The place where the mail goes. The actual machine name is required no
# MX records are consulted. Commonly mailhosts are named

# Where will the mail seem to come from?

# The full hostname

# 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

Create aliases for local usernames (optional)

edit the /etc/ssmtp/revaliases file

sudo nano /etc/ssmtp/revaliases

And add into it the desired translation which in our Gmail examples case will be

From now on, the machine will Email when requested through command line or script.

Check setup

Lets test that our ssmtp setup was correct by sending an Email

echo "Test message from Linux server using ssmtp" | sudo ssmtp -vvv

The “-vvv” turns on verbosity output.


Unfortunately a few thing can go wrong.

  • Check username and password again

  • Check google is not blocking your new device

EmailAlerts (last edited 2017-05-11 22:03:33 by evilnick)