Any output (to stdout
and stderr
) generated by a crontab task will be sent to you by email.
This is great to generate system reports or be alerted when something goes wrong.
By default crontab (and the MTA it relies on) will use a text/plain
MIME type.
But you can make crontab tells the mail sender to use another MIME type, like text/html
.
Open crontab with crontab -e
, and add this line:
CONTENT_TYPE="text/html; charset=utf-8"
That’s it! Now crontab will ensure your email is sent as HTML. This means you can have your crontab script to output HTML code (best to do that with a templating lib, like handlebars), and it will be rendered as proper HTML by your email client. .
Note: Only recent version of crontab support this feature. Run man 5 crontab
on you system to double-check.