I've recently got Postfix working as a send only MTA relaying through Google Workspace (formerly Google G Suite). I would now like to send emails after completed cron jobs to my personal email. The problem I initially faced was that my server was sending out two emails, one to personal-email@hotmail.com
and the other to root@example.com
with the latter bouncing back a MAILER-DAEMON reply as this account doesn't exist.
This was my initial cron job located at /etc/cron.d/google-drive-backup
:
59 11 * * * root /root/scripts/google-drive-backup.sh && mail --append="From:Root <no-reply@example.com>" --append="Reply-To:webmaster@example.com" personal-email@hotmail.com
I did research on these forums and came across suppressing the output by using >/dev/null 2>&1
which works if I place it directly after the script:
59 11 * * * root /root/scripts/google-drive-backup.sh >/dev/null 2>&1
I can confirm no emails are being sent as the mail log at /var/log/mail.log
is empty. However, suppressing the output has no affect when using it in conjunction with the mail
command:
59 11 * * * root /root/scripts/google-drive-backup.sh >/dev/null 2>&1 && mail --append="From:Root <no-reply@example.com>" --append="Reply-To:webmaster@example.com" personal-email@hotmail.com
or
59 11 * * * root /root/scripts/google-drive-backup.sh && mail --append="From:Root <no-reply@example.com>" --append="Reply-To:webmaster@example.com" personal-email@hotmail.com >/dev/null 2>&1
Essentially I would like to disable crontab's default email feature and use sendmail so that I can customise the subject and email headers.