Setup sSMTP on Mint Linux

How To Setup Email Alerts on Mint Linux Using sSMTP

Here’s how to setup mail and ssmtp to send alerts to your gmail account.

This technique is meant for your Linux box sitting in your house acting as a home server. In fact, since many home ISPs block regular outbound email, you might find this technique a great way to ensure you still get administration emails, even from your home servers.

Overview

Configuring the Email sending ability for a machine immediately gives us the upshot that a lot of the system’s administration problems and critical alerts will be automatically sent to that system’s designated administrator. The most noteworthy example is that cron job execution errors fall into this category and therefore will notify the admin that there was a problem with scheduled jobs such as backups as soon as they happen including the standard error (stderr) output in the report. We will also be able to incorporate emailing from bash scripts.

Don’t worry—it usually doesn’t spam you with too much information and you can just de-configure it if it becomes to annoying.

On Debian based systems, other then a lot of very versatile emailing related programs there is also the ssmtp package, which is well suited if all you want to do is have an agent to send emails using another email server (MTA), without having to setup an entire postfix or sendmail configuration to do so.

Prerequisites and assumptions

Before we get started, you’ll want to make sure that all of these conditions are met:

  • You have an SMTP server that can receive the emails from your machines and send them to the recipient (i.e. your corporate exchange or Gmail).
  • You have the credentials for a user that is able to send Email on that server (i.e. a mailbox or a Gmail account).
  • This procedure has been used and tested on Mint.
  • You will see me use gedit as the editor program, this is just because I’m used to it… you may use any other editor that you’d like.

Setup

To install the ssmtp (Simple S.M.T.P) package, use the following command:

sudo apt-get install ssmtp

Now edit config file:

sudo gedit /etc/ssmtp/ssmtp.conf

Config ssmtp.conf file for sSMTP

# Config file for sSmtp
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
#root=postmaster

# MX records are consulted. Commonly mailhosts are named mail.domain.com
#mailhub=mail
mailhub=smtp.gmail.com:587
AuthUser=Gmail username
AuthPass=Gmail password

#For TLS and SSL
UseSTARTTLS=YES

# Where will the mail seem to come from?
#rewriteDomain=
rewriteDomain=gmail.com

# The full hostname
#hostname=MyMediaServer.home
hostname=username@gmail.com

# Are users allowed to set their own From:?
# YES - Allow the user to specify their own From:
# NO - Use the system generated From: address
FromLineOverride=YES

Now edit a new config file:

sudo gedit /etc/ssmtp/revaliases

Insert

root:username@gmail.com:smtp.gmail.com:587
user:username@gmail.com:smtp.gmail.com:587       // note:  $ whoami      # gives user

Confirming setup

 

sudo apt-get install mailutils

Now you can test something like this.

sudo df -h | mail -s "Disk Info" username@gmail.com

If all goes well, you should be getting the Email in a couple of seconds.

To troubleshoot start with checking your mail log.

sudo tail -f /var/log/mail.log

Setup Sendmail Wamp Server

Download fake sendmail from http://glob.com.au/sendmail/Click Here then follow these instructions http://blog.techwheels.net/send-email-from-localhost-wamp-server-using-sendmail/Click Here. One note this gave me an error at first but just edit your php.ini at the end of file just add sendmail_path = “C:\wamp\sendmail\sendmail.exe -t -i” and smtp_port = 465. I had to add smtp_port = 465 or it defaulted to port 25 and didn’t work.