Score:0

How to change FROM name with mailutils?

cn flag

I have a script that sends email with some server info regularly. I use following command within a script

cat $msg |mail -r script1@my.domain.com -s "server event" myemail@adress.com

The problem with Ubuntu machines is they always put "root <script1@my.domain.com>" in FROM header, so when I receive email it just says from root.
Since I have many different machines I would like to see email address. Within Fedora works normally with same command, and email has only email address as From header.
I've tried to use -r Script1 <script@my.domain.com> (gives an error) or -u Script1 -r script@my.domain.com but result is the same. mail appends name "root" to From header so I only see as email from root.

Score:0
cn flag

I found a solution when putting all in one line:

cat $msg |mail -a "From: Script1 <script1@my.domain.com>" -s "server event" myemail@adress.com

but if I use variable for From: field, it keeps giving me an error.

msg="Message to send"
EMTO="myemail@address.com"
EMFR='-a "From: Script1 <script1@my.domain.com>"'
cat $msg |mail $EMFR -s "server event" $EMTO

mail: Cannot parse address `<Script1@my.domain.com>"' (while expanding `<script1@my.domain.com>"'): Malformed email address

Closest I can get to working option is defining just email like following:

msg="Message to send"
EMTO="myemail@address.com"
EMFR="Script1 <script1@my.domain.com>"
cat $msg |mail -a "From: $EMFR" -s "server event" $EMTO

I would like to avoid modifying mail command, as I have a lot o them through out each script, whereas email addresses are defined only on top. Any clues?

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.