07.06.2023

How to Set Up Cron Notifications to Email on Ubuntu 20.04

We have already covered setting up automatic scheduled tasks using cron in Ubuntu 20.04. In this tutorial we will look at an additional handy feature and set up sending Cron notifications to email.

Server preparation

First, you need to configure your server to be able to send emails. You can go through the steps in this tutorial - Postfix configuration as a Send-Only SMTP Server.

Following the instructions in the first two steps should be sufficient for our purposes. However, some mail servers will put unencrypted emails in the Spam folder or reject altogether.

Therefore, if you will not receive notifications as a result of following the steps in this guide, try checking your junk mail folder and enabling SMTP encryption (step 4 of the Postfix configuration guide).

To check the server's email logs, see:

cat /var/log/mail.log

Set up sending Cron notifications to email

Open the Cron configuration file.

crontab -e

Place this config in it. Replace the email address with yours.

MAILTO="mail@domain-name.com"
SHELL=/bin/bash
HOME=/
* * * * * echo "Message from Ubuntu cron"

Screenshot 1. Cron email notification.