26.05.2023

How to Set Up Cron Notifications to Email on CentOS 8

We recently looked at Cron configuration on CentOS 8. It has another useful option, and we'll talk about it now. In this tutorial, we will set up sending Cron notifications to email on CentOS 8.

Before cron can send email notifications, you need to configure an SMTP server. We covered Postfix configuration in this tutorial.

Cron configuration

To enable sending cron notifications to email, open the cron scheduler.

crontab -e

Paste these lines there and enter your email address to receive notification.

MAILTO="recipient@domain.com"
SHELL=/bin/bash
HOME=/
* * * * * echo "Test email from cron"

The result of all configured tasks will be sent to the specified email address.

Screenshot 1. Test email notification from cron.

If you don't receive any notifications, look in the Spam folder. You can also look at the email logs to see why.

cat /var/log/maillog

Some mail servers have such strict spam checks that additional outgoing server settings are required. For example, adding a DNS PTR record for the domain name. To do this, you need to contact the support team of the company that provides you with a public IP address.

Additional measures to increase trust in correspondence from your server are to enable DKIM signature for your messages, add SPF and DMARC records for your domain.