Simple outgoing email on Ubuntu Server using sSMTP

Many of us have some sort of Linux/Ubuntu server running some sort of service.   When all is running smoothly all is good.  But there are times when the server would want to notify you of some warning or serious problem (Disk getting full,  cron job failure,  raid disk failure…).

The reason why many of our servers do not send us email with those notifications is that your basic mail server can be intimidating to setup (and frankly overly complicated for the simple task at hand).

Enter sSMTP which will allow you to setup OUTGOING email quick and easy!   In this post, we will learn how to install sSMTP on a Ubuntu server and configure it to send email through one of the following email service provider:  Gmail, Cox.net, Dreamhost and Rackspace mail.

NOTE: If reading this in the context of building a home NAS box (or other server requiring the use of “mdadm”, please install this AFTER mdadm as the later will install postfix and we want to replace it with sSMTP here.

When researching a simpler alternative to using postfix (automatically installed when you install mdadm on ubuntu), I came accross sSMTP and mSMTP.   A little more research seemed to indicate that sSMTP was the more popular of the two with more articles and tutorials.

The instructions in this post are for Ubuntu systems but the ssmtp package is available for other Linux and BSD variants.    First, if you have installed mdadm your system probably already has Postfix installed.    The first step is to remove it:

sudo apt-get purge postfix

Then install ssmtp and a simple command line mail client for testing your setup:

sudo apt-get install ssmtp heirloom-mailx

Next, edit the description field in your /etc/passwd file to make outgoing system email more informative (i.e. instead of saying the mail comes from “root”, it will say “root_On_MyNasServerName” (mine is called “lnas”):

sudo emacs /etc/passwd    (or use your favorite editor)
Change line
From:   root:x:0:0:root:/root:/bin/bash
To be:  root:x:0:0:root_On_lnas:/root:/bin/bash

This field is just a comment field and will not alter the functionality of your system.    Then edit the configuration file:

sudo emacs /etc/ssmtp/ssmtp.conf

Replace the content of the config file with one of the following sample configuration and replace the information with your own account info.  You can also use one of them as the basis for your own ISP specific configuration.

Sample ISP configuration files:

Rackspace Mail:

# Config file for sSMTP sendmail - Rackspace Mail
MailHub=secure.emailsrvr.com:465      # SMTP server hostname and port  (port 465 in this case)
UseTLS=YES                            # Secure connection (SSL/TLS)
FromLineOverride=YES                  # Force the From: line
Hostname=lnas                         # The name of this host
RewriteDomain=lnas.scoobhome.com      # Theoretically, host the mail appears to be coming from
Root=Username@SomeDomain.com          # Redirect mail for root@ (CRON) to this address
AuthUser=USER@mDomainName.com         # Your Rackspace mail address
AuthPass=XXXXXX                       # The password for the mail account

Cox Cable (ISP):

# Config file for sSMTP sendmail - TSL / COX.net
# NOTE: COX.net forces us to use plain cox.net under both hostname and RewriteDomain
######
MailHub=smtp.west.cox.net:465 # SMTP server hostname and port  [For West coast Cox]
UseTLS=YES                    # Secure connection (SSL/TLS)
FromLineOverride=YES          # Force the From: line
Hostname=cox.net              # NOTE: COX REQUIRES this to be cox.net in order to work
RewriteDomain=cox.net         # host email appears to be coming from - COX requires this as cox.net
Root=Username@SomeDomain.com  # Redirect to root (CRON) to this addr EX: myNasRoot@MyDomain.com
AuthUser=username             # Your Cox mail username (EX: just bob, not bob@cox.net)
AuthPass=password             # The password for the mail account

Cox Cable (Internet ISP) – Unauthenticated:

MailHub=smtp.west.cox.net    # SMTP server host/port  [WEST coast Cox] - If no port, defaults to 25
FromLineOverride=YES         # Force the From: line
Hostname=cox.net             # NOTE: Cox requires this and RewriteDomain to be Cox.net
RewriteDomain=cox.net        # The host the mail appears to be coming from
Root=Username@SomeDomain.com # Redirect root email/(CRON) to this email EX: myNasRoot@MyDomain.com

Dreamhost (ISP):

MailHub=mail.YourDomain.com:465    # SMTP server host and port - Your DREAMHOST hosted domain
UseTLS=YES                         # Secure connection (SSL/TLS)
FromLineOverride=YES               # Force the From: line
Hostname=lnas                      # The name of this host
RewriteDomain=scoobhome.com        # Theoritically, host the mail appears to be coming from
Root=Username@SomeDomain.com       # Redirect root email/(CRON) to this email EX: myNasRoot@MyDomain.com
AuthUser=username@YourDHdomain.com # Your DreamHost mail account  (Bob@acme.com)
AuthPass=password                  # The password for the mail account

Gmail:

mailhub=smtp.gmail.com:465   # SMTP server for Gmail
UseTLS=YES
FromLineOverride=YES         # optional
Root=Username@SomeDomain.com # Redirect root email (CRON) to this email EX: myNasRoot@MyDomain.com
AuthUser=USER@gmail.com
AuthPass=YourGmailPassword

 

Your Own ISP:

When you set things up for your own ISP, don’t give up!   It can be a little frustrating at times to get this working but perseverance and trying little variations one at a time will invariably yield some positive results.    For that reason, once you get thing working for your ISP,  please share with others by posting your config file (edit out your name/username/passwd) in the comment field.

Testing your setup:

From the command line type:
   # mail you@yourEmail.com

The mailer program will ask you for a Subject line then it will show you a blank line.  Type in your email, hit Enter at the end of each line.  When you are done, enter a single period “.” on a blank line and hit Enter.   Then check your email to see if things worked.   A word of advice.  You may want to run a test first from your desktop email program to see how long it takes your mail server to process received emails.   There is nothing more frustrating than to thinker with your config file thinking things are not working only to find a half doze successful email showing up in your mailbox 10 minutes later!

References:

 

 

 

About admin

My name is Christian Marcotte.
I live in San Diego with my wife Carolyn and our son Jeremiah.

This site is a recording of my currrent ponderings, hobbies and interest.

This entry was posted in Linux, NAS, Software. Bookmark the permalink.

One Response to Simple outgoing email on Ubuntu Server using sSMTP

  1. Just wanted to say a quick “thanks for this” and give future visitors a heads up on one issue I faced:

    I found out that you can’t have certain special characters in your password. My password had a + and an = in it, and it kept failing authentication. Seems others have had this same issue. I generated a new alpha-numeric password and it worked perfectly.

Leave a Reply

Your email address will not be published. Required fields are marked *