system:cron
Crontab
Problem: Email From Address
When setting up the crontab it's possible to define a MAILTO address, however it's not possible to define a from address. Especially gmail will complain about a from address reading 'root@mail.example.com'
To work around this problem it's necessary to move the functionality to external scripts instead. letsencrypt has been used as an example but the same can be done for other recurring tasks.
First add the following line to your crontab:
MAILTO=""
This disabled crontabs built-in email feature.
Make sure mutt is installed and setup as in msmtp
Next create a script which will call letsencrypt (certbot)
#!/bin/bash
# get output of command
OUTPUT=$(/usr/bin/certbot renew 2>&1)
# send email with output
echo "${OUTPUT}" | mutt -s "Crontab from mail server" -- johnDoe@example.com
add your script to crontab. e.g.
4 5 * * 1 /usr/local/bin/check-letsencrypt.sh
system/cron.txt ยท Last modified: 2022/06/10 19:19 by 127.0.0.1