How to: Use sSMTP to Send Outbound Email

sSMTP is a simple MTA (mail transfer agent) to deliver mail from a computer to a mail hub (SMTP server). sSMTP is simple and lightweight, there are no daemons or anything hogging up CPU; Just sSMTP. Unlike Exim4, sSMTP does not receive mail, expand aliases, or manage a queue.

How to: Use sSMTP To Send Outbound Email

You can use sSMTP to send emails directly from the command line. sSMTP requires an SMTP mail server to function. For this example we'll be making use of Gmail’s SMTP server.

Installing sSMTP

1. sSMTP is available to install from the built in APT package manager. First we will update the packages and then install sSMTP.

apt-get update
apt-get install ssmtp

Configuring sSMTP

1. You can use your favorite text editor to configure the ssmtp.conf file. In this case we are using nano.

nano /etc/ssmtp/ssmtp.conf

2. In order to use Gmail’s SMTP server configure sSMTP with the following parameters.

# 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

Note: If you do not know your VPS hostname you can print it to the terminal by running


Testing sSMTP

You can test if sSMTP is working running the following command


This will start the sSMTP process you can format the email as follows
Subject:This is an sSMTP Test Email
I am testing sSMTP.

Press Ctrl-D when you are finished writing the body and sSMTP will send the Email.

Additional Security Steps

For security purposes it is a good idea to create another user to send mail with if other people have access to the computer. Your Gmail password is left unencrypted in the ssmtp.conf file!

To create a new user run the adduser command

adduser username

Make sure you have a strong root password and hardened network security settings.

1. Changing file permissions

chown root:mail /etc/ssmtp/ssmtp.conf
chmod 640 /etc/ssmtp/ssmtp.conf

2. Add the user to the mail group

usermod -a -G mail username

3. Log out of all sessions and log back in to test the changes

Subject:This is an sSMTP Test Email
I am testing sSMTP!

Changing Google App Settings

If your message does not send it may be filtered by Google’s secure App settings. You can disable these at the following link.

Sending Predefined .txt Emails

You can send predefined emails from .txt files using the following format and command:

1. Create an example.txt file with a text editor

nano example.txt
Subject:This is a test
Hello this is a test sSMTP email.

2. Send the contents of the example.txt file by running.

ssmtp < example.txt

You now know how to send emails from the command line using sSMTP!

For additional resources on specifics of using sSMTP, please consult sSMTP Support and Community reference material:

sSMTP Debian Wiki

sSMTP Man Pages

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.