See crontab guide.

Send stdout and stderror to stdout and mail the result. Useful in a cronjob. Note this assumes global mail is disabled with MAILTO=''.

RESULT="$(cd DIR && COMMAND)"; [[ $? -ne 0 ]] || echo "$RESULT" | mail -s 'Task foo failed!' $USER