sSMTP gebruiken met Ubuntu

Voor het volledige artikel kijk je op bijgeplaatste sites:

sSmtp is an extremely simple, resource conserving, SMTP server that will allow your desktop or server to send email. In this article we are going to use sSMTP to send email through Gmail.

Sometimes we want to enable our servers/desktops to be able to send email without setting up a full featured mail server or configuring postfix to route through Gmail.

sSmtp is an extremely simple, resource conserving, SMTP server that will allow your desktop or server to send email. In this article we are going to use sSMTP to send outgoing email through Gmail.

Install sSMTP

Debian/Ubuntu users can Install with this command or click here to open up apt:

sudo apt-get install ssmtp

We need to then need to edit, ‘/etc/ssmtp/ssmtp.conf’:

Then add each account that you want to be able to send mail from by editing, ‘/etc/ssmtp/revaliases‘:

Now try sending an email

You can send an email through your favorite email client, like ‘mutt‘, or type:

sudo ssmtp

You will then type your message, hit enter and ‘ctrl+d

Now that you have a simple outgoing email server setup, you can do all sorts of neat things:

  • Configure cron jobs to send log reports to your email address
  • Alert you of all kinds of system changes
  • Send email alerts when your computer reaches a certain temperature
  • Send email through PHP, Python, Ruby, and Perl


Just wanted to mention that if your using sSMTP from the CLI, that the format should look like this;

sudo ssmtp

Subject: enter_subject_here

enter_body_here (then press enter when done to get a newline)
Then press ctrl-D


Don’t use ’sudo’ unless you want your emails to appear from ‘root’.

Add ’smtp’ directory to the PATH of your normal USER, and run as normal user.

(Edit ‘/etc/ssmtp/revaliases’ with your normal user name as “localusername”, as in tutorial.)


Wouldn’t it be useful if your computer could email you? I’d like to be notified by email when my server is in trouble, but I don’t want to run my own mail server. sSMTP is perfect for this; it’s a simple way to send email from your system to an SMTP mail server, like Gmail’s.

Here’s how I set up sSMTP on Ubuntu to send mail through my Gmail account.

Install sSMTP from the package ssmtp (click the link to install), or by running the command below in your terminal:
sudo apt-get install ssmtp

sSMTP can be configured from one text file. Open /etc/ssmtp/ssmtp.conf in a text editor:
sudo gedit /etc/ssmtp/ssmtp.conf

The configuration file is very short and well commented by default. Here’s the options I use for sending mail through Gmail:

If you’re using Gmail like I am, change the root, authuser, and authpass options to the email address, username, and password of your Google account. If you’re using another mail service you’ll need to change mailhub to the relevant SMTP server.

Once your configuration work is done, time to try sending some mail! The simplest way to do this is to run sSMTP in a terminal with a recipient email address:

sSMTP will then wait for you to type your message, which needs to be formatted like this:
Subject: test email

hello world!

Note the blank like after the subject, everything after this line is the body of the email. When you’re finished, press Ctrl-D. sSMTP may take a few seconds to send the message before closing.

Now it’s easy to write scripts which can send you mail. Here’s an example terminal command to send an email from the msg.txt text file:
ssmtp < msg.txt

msg.txt is a simple text using the proper formatting for sSMTP:
Subject: alert

The server is down!


Well, I don’t know about php, on says it just needs a working mail system, so if you need to know only how to write the ssmtp.conf file, then I can help you with that. ssmtp will allow you to send mail directly from your computer through an external smtp server.
A working ssmtp.conf file:

root=postmaster #you probably won’t need to change it #eg.
hostname=what.goes.after.@.inyourmail #eg. #for the stmp account
AuthMethod=LOGIN # or CRAM-MD5

(ssmtp supports only these two authentication methods, check more at the manuals)

Geplaatst in Linux, Server beheer, Ubuntu
%d bloggers liken dit: