FreeBSD mail From: override sender name

Hello.
Monitoring script.
Mailing function.
How to override the sender name?
On Linux script works.
mail -s "Sites is works $DT." -aFrom:info@mon.tes.com $MAIL < sh/tes_s_check/up.txt
The mail utility does not have the -a option on a FreeBSD system.
I did not find.:
-a, --append=HEADER: VALUE append given header to the message being sent
How to on system FreeBSD utilit mail From: override sender name?
 
Instead of using a tool like mail(1), feed the mail directly to your local MTA, which accepts a whole mail including headers on standard input. It's called sendmail by convention, even when provided by a different software, so this will work on any system that has a local MTA installed:
Bash:
#!/bin/sh

SENDMAIL=/usr/sbin/sendmail
FROM=${1:-foo@bar.invalid}
TO=${2:-info}

${SENDMAIL} ${TO} <<EOF
From: ${FROM}
To: ${TO}
Subject: Test

foo bar baz!
.
EOF

Also note the From header is not the same as the sender. From is what's written inside the mail, while the sender is what's e.g. used in SMTP dialogs (and added as a return-address to the mail before final delivery). If you want to change the sender as well, use the -f option to sendmail. But be aware this might be rejected, depending on the configuration of your MTA.
 
Also note the From header is not the same as the sender. From is what's written inside the mail, while the sender is what's e.g. used in SMTP dialogs (and added as a return-address to the mail before final delivery). If you want to change the sender as well, use the -f option to sendmail. But be aware this might be rejected, depending on the configuration of your MTA.
I know about sendmail.
 
Uhm, what you quoted wasn't about sendmail specifically, more about Email in general, plus the sendmail CLI, which is quasi-standard for an MTA (e.g. dma(8), exim, postfix all implement it). As you were talking about the "sender" while refering to the From: header, I assumed there might be some confusion 🙈 – if there isn't and you're fine with something different in From: than in the actual sender, perfect, then I guess you have your solution? ;)
 
Back
Top