Problem: when I use the mail
command under linux (Ubuntu Server 16.04) as root to send an email (several scripts on my server do so), the From:
field in the mail header looks like From: root@mydomain.org
. I want it to look like From: admin@mydomain.org
.
Attempt: I already found the option -a "From: admin@mydomain.org"
to add the field to the mail header.
My whole command looks like this:
echo "content" | mail -s "subject" "recipient@wherever.org" -a "From: admin@mydmain.org"
Second Problem: However, I do not want to write the -a
option at every point I use the mail
command in a script because this is some kind of hard coding.
Second Attempt: My best attempt yet is to write a wrapper, though I think there should be a cleaner method to always add that header field to mails sent with the mail
command.
Question: Does anyone know a better way which does not include hard coding? Still I want to use such a simple command line as above to not make things unnecessary complicated.
Best
Fabian