How to set the From email address for mailx command? How to set the From email address for mailx command? shell shell

How to set the From email address for mailx command?


You can use the "-r" option to set the sender address:

mailx -r me@example.com -s ...


The "-r" option is invalid on my systems. I had to use a different syntax for the "From" field.

-a "From: Foo Bar <foo.bar@someplace.com>"


In case you also want to include your real name in the from-field, you can use the following format

mailx -r "me@example.com (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 "me@example.com (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!