How to set the From email address for mailx command?
In case you also want to include your real name in the from-field, you can use the following format
mailx -r "[email protected] (My Name)" -s "My Subject" ...
If you happen to have non-ASCII characters in you name, like My AEÆoeøaaå (Æ= C3 86, ø= C3 B8, å= C3 A5), you have to encode them like this:
mailx -r "[email protected] (My =?utf-8?Q?AE=C3=86oe=C3=B8aa=C3=A5?=)" -s "My Subject" ...
Hope this can save someone an hour of hard work/research!
You can use the "-r" option to set the sender address:
mailx -r [email protected] -s ...
On debian where bsd-mailx
is installed by default, the -r
option does not work. However you can use mailx -s subject [email protected] -- -f [email protected]
instead. According to man page, you can specify sendmail options after --
.
The "-r" option is invalid on my systems. I had to use a different syntax for the "From" field.
-a "From: Foo Bar <[email protected]>"