Skip to content

Instantly share code, notes, and snippets.

@nepsilon
Last active February 19, 2017 13:52
Show Gist options
  • Save nepsilon/342fb6436372151b03a181603efc27de to your computer and use it in GitHub Desktop.
Save nepsilon/342fb6436372151b03a181603efc27de to your computer and use it in GitHub Desktop.
Make crontab send you HTML emails — First published in fullweb.io issue #57

Make crontab send you HTML emails

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment