Feb 292012

A bit old, but still really useful, i used this method on a server. Article by Tom, first posted on Tombuntu

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 on Debian/Ubuntu), 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:
[email protected]
AuthMethod=LOGIN # This is needed only for 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 [email protected]

sSMTP will then wait for you to type your message, which needs to be formatted like this:
To: [email protected]
From: [email protected]
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 [email protected] < msg.txt

msg.txt is a simple text using the proper formatting for sSMTP:
To: [email protected]
From: [email protected]
Subject: alert

The server is down!

Popular Posts:

Flattr this!

  5 Responses to “Sending Email From Your Linux System with sSMTP”

  1. @Rickyx.. Yeah I’m using sendEmail too… that is very easy to use

  2. hi! I’m trying with my mail server on other lan host,so it’s not gmail but It not work 🙁 it said that our server not support auth login with error 502.2.2.

  3. ODIO SENDMAIL. Non esiste una cakkio di guida decente che spieghi in maniera semplice come cakkio inviare una fottutissima email da terminale. Devo partire tra due giorni e non me ne sbatte niente della storia di sendmail. E non funziona. Maledetta filosofia per cui uno deve per forza avere problemi prima di poter usare un programma, o capirne per forza il funzionamento intrinseco. Doverlo fare per forza è l’equivalente del non poterlo fare.
    GRAZIE per questo post. 2 minuti e tutto funziona…. grazie grazie grazie.
    E quando avrò 10 ore libere mi leggerò pure il manuale del maledetto sendmail!

  4. This is the shortest and simplest way to send mail. You saved me after 2 days of fighting with postfix and sendmail (wondering why they make them that complicated). I had scrolled through long pages of tutorials then came here only to find no scrolling is needed. Thanks a lot.

    David, Uganda

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>