I'm writing a bash script that will email an alert when various system resources are used beyond a certain threshold.
I've set the script to make the first line of the email body "From: ALERTS alerts@mydomain.com" (and I've made sure the server's linux hostname is mydomain.com)
But mail delivery fails, and the postfix logs seem to indicate the email is being sent with root@mydomain.com as the from address, which I suspect is what's preventing delivery.
fwiw emailing from/to these accounts/domains works fine when I use an email client, it's only when sending from the linux server that mail delivery fails.
Here's the bash script:
NL=$'\n'
DNL=$'\n\n'
# compose email for admin notification
EM_BODY="From: ALERT <alerts@mydomain.com>${NL}"
EM_BODY+="Subject: WARN: sustained high CPU load${DNL}"
# add general description of alert
EM_BODY+="WARNING: CPU load on linux server higher than 90% for more than 15 second
# add snapshot of CPU usage
EM_BODY+="$(ps -eo user,tty,pid,cmd:80,%cpu --sort=-%cpu | head -n 15)${DNL}"
# specify recipient address
MAILTO="myself@myotherdomain.com"
# send email
echo "$EM_BODY" | /usr/sbin/sendmail -t $MAILTO
...and here's the postfix log output (with domain names replaced):
Aug 1 14:48:47 mydomain postfix/error[229579]: 34597FCD50: to=<myself@myotherdomain.com>, relay=none, delay=64951, delays=64951/0.11/0/0, dsn=4.4.1, status=deferred (delivery temporarily suspended: connect to eforward5.registrar-servers.com[162.255.118.51]:25: Connection timed out)
Aug 1 14:48:47 mydomain postfix/error[229571]: 8476CFCC48: to=<myself@myotherdomain.com>, relay=none, delay=98671, delays=98670/0.11/0/0.01, dsn=4.4.1, status=deferred (delivery temporarily suspended: connect to eforward5.registrar-servers.com[162.255.118.51]:25: Connection timed out)
Aug 1 14:48:47 mydomain postfix/error[229583]: 6A19DFCCF9: to=<myself@myotherdomain.com>, relay=none, delay=77431, delays=77431/0.11/0/0.01, dsn=4.4.1, status=deferred (delivery temporarily suspended: connect to eforward5.registrar-servers.com[162.255.118.51]:25: Connection timed out)
Aug 1 14:48:47 mydomain postfix/error[229575]: 95128FCD40: to=<myself@myotherdomain.com>, relay=none, delay=69150, delays=69150/0.11/0/0.01, dsn=4.4.1, status=deferred (delivery temporarily suspended: connect to eforward5.registrar-servers.com[162.255.118.51]:25: Connection timed out)
Aug 1 14:50:17 mydomain postfix/pickup[228607]: 055FBFCDB6: uid=0 from=<root>
Aug 1 14:50:17 mydomain postfix/cleanup[229640]: 055FBFCDB6: message-id=<20220801145017.055FBFCDB6@mydomain.com>
Aug 1 14:50:17 mydomain postfix/qmgr[156914]: 055FBFCDB6: from=<root@mydomain.com>, size=363, nrcpt=1 (queue active)
Aug 1 14:50:17 mydomain postfix/error[229570]: 055FBFCDB6: to=<myself@myotherdomain.com>, relay=none, delay=0.03, delays=0.02/0/0/0.01, dsn=4.4.1, status=deferred (delivery temporarily suspended: connect to eforward5.registrar-servers.com[162.255.118.51]:25: Connection timed out)
Aug 1 14:50:23 mydomain postfix/pickup[228607]: 67708FCDB7: uid=0 from=<root>
Aug 1 14:50:23 mydomain postfix/cleanup[229640]: 67708FCDB7: message-id=<20220801145023.67708FCDB7@mydomain.com>
Aug 1 14:50:23 mydomain postfix/qmgr[156914]: 67708FCDB7: from=<root@mydomain.com>, size=2071, nrcpt=1 (queue active)
Aug 1 14:50:23 mydomain postfix/error[229573]: 67708FCDB7: to=<myself@myotherdomain.com>, relay=none, delay=0.01, delays=0.01/0/0/0, dsn=4.4.1, status=deferred (delivery temporarily suspended: connect to eforward5.registrar-servers.com[162.255.118.51]:25: Connection timed out)
Aug 1 14:52:16 mydomain postfix/pickup[228607]: 9FD06FCDB8: uid=0 from=<root>
Aug 1 14:52:16 mydomain postfix/cleanup[229720]: 9FD06FCDB8: message-id=<20220801145216.9FD06FCDB8@mydomain.com>
Aug 1 14:52:16 mydomain postfix/qmgr[156914]: 9FD06FCDB8: from=<root@mydomain.com>, size=363, nrcpt=1 (queue active)
Any insight would be appreciated!