Change the "From:" address in Unix "mail"
In my version of mail ( Debian linux 4.0 ) the following options work for controlling the source / reply addresses
- the -a switch, for additional headers to apply, supplying a From: header on the command line that will be appended to the outgoing mail header
- the $REPLYTO environment variable specifies a Reply-To: header
so the following sequence
export REPLYTO=cms-replies@example.commail -aFrom:cms-sends@example.com -s 'Testing'
The result, in my mail clients, is a mail from cms-sends@example.com, which any replies to will default to cms-replies@example.com
NB: Mac OS users: you don't have -a , but you do have $REPLYTO
NB(2): CentOS users, many commenters have added that you need to use -r
not -a
NB(3): This answer is at least ten years old(1), please bear that in mind when you're coming in from Google.
GNU mailutils's 'mail' command doesn't let you do this (easily at least). But If you install 'heirloom-mailx', its mail command (mailx) has the '-r' option to override the default '$USER@$HOSTNAME' from field.
echo "Hello there" | mail -s "testing" -r sender@company.com recipient@company.com
Works for 'mailx' but not 'mail'.
$ ls -l /usr/bin/maillrwxrwxrwx 1 root root 22 2010-12-23 08:33 /usr/bin/mail -> /etc/alternatives/mail$ ls -l /etc/alternatives/maillrwxrwxrwx 1 root root 23 2010-12-23 08:33 /etc/alternatives/mail -> /usr/bin/heirloom-mailx