Prasad Pawar

Apr 30, 2020

2 min read

Setup SSMTP on Ubuntu servers with crontab

Learn how to set up the standalone job on Linux using Crontab and SSMTP to sent status out to you

Photo by [Muukii]( on [Unsplash](

Photo by Muukii on Unsplash

First of all, you need a Linux machine to make this happen! On most of Linux distros crontab is available by default, specifically on servers. But anyway we will start this tutorial from scratch assuming you don’t even have crontab available.

Installing Crontab

apt-get update && apt-get upgrade

Install cron

apt-get install cron
systemctl status cron
● cron.service - Regular background program processing daemon
Loaded: loaded (/lib/systemd/system/cron.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2019-07-02 20:38:53 IST; 4 days ago
Docs: man:cron(8)
Main PID: 978 (cron)
Tasks: 1 (limit: 4915)
Memory: 2.0M
CGroup: /system.slice/cron.service
└─978 /usr/sbin/cron -f

this shows your crontab is working fine.

Now let's try editing the crontab, use root *if you need any *sudo to be used in your script. Depending on your need you can use *crontab -e *for different users on the system and every user has its own crontab installed.

crontab -e
(choose nano or any other editor of your choice, if asked)
Adding below contents at the end of the file
* */12 * * * bash /home/rocking-shell/

Save above file, and crontab will say, installing crontab

This means your crontab is setup now, more details here

Installing SSMTP

apt install ssmtp

Now edit SMTP configurations here

sudo vi /etc/ssmtp/ssmtp.conf

# 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

Make sure when you use Gmail, you need to enable less secure apps in settings, you can check this here

Let's try testing the ssmtp by sending an email

nano mail-sample.txtenter below contents to itTo: 
Subject: test email from ssmtp!
now run ssmtp**ssmtp < mail-sample.txt**

Yaayy! You are done. Please let me know in the comments if you face any issues or need any help.