Sending an Email Report with Cron
Set MAILTO at the top of the crontab and cron emails any job output to that address. For full control, pipe your report into the mail command. Both need a working local MTA (like postfix or msmtp).
MAILTO: auto-email job output
At the top of crontab -e:
MAILTO=you@example.com0 8 * * * /opt/app/report.sh
Any output the job prints is emailed to you. Silent jobs send nothing.
Pipe to the mail command
For a subject line and explicit control:
0 8 * * * /opt/app/report.sh | mail -s 'Daily report' you@example.com
No email arriving?
Cron can only hand mail to a local MTA. Install and configure postfix or msmtp first, and check /var/log/mail.log. Without an MTA, MAILTO does nothing.
FAQ
How do I send an email from a cron job?
Set MAILTO=you@example.com at the top of the crontab, or pipe output to mail -s 'Subject' you@example.com. Both need a local MTA.
Why is MAILTO not sending mail?
Cron hands mail to a local MTA. If postfix or msmtp isn't installed and configured, nothing is delivered. Check /var/log/mail.log.
How do I set the subject of a cron email?
Pipe the output into mail with -s: /opt/app/report.sh | mail -s 'Daily report' you@example.com.