Debian – Cronjob change email subject and sender name

crondebianemail

I have a cronjob setup using crontab that looks like this…

MAILTO=myemail@example.com
00 02 * * * /home/myaccount/myscript.sh

This works great and at 2AM it runs the script and emails me the output to myemail@example.com

The only issue is that the email subject and the name of the sender aren't very useful.

Is there a way to change them in the same way i can set the recipient email address?

Can I suppress the automatic email and pipe the output to mail myself?

Best Answer

Cron doesn't allow for a lot of configuration, but you can do this, assuming you have the mailutils package installed:

00 02 * * * /home/myaccount/myscript.sh 2>&1 | mail -s "My subject" $MAILTO