views:

720

answers:

6

Does anyone know how to change the from user when sending email using the mail command? I have looked through the man page and can not see how to do this.

We are running Redhat Linux 5.

A: 

mail -r [email protected] -R [email protected]

-r = from-addr -R = reply-to addr

The author has indicated his version of mail doesn't support this flag. But if you have a version that does this works fine.

The -r is not a valid option for the mail command option for the version of mail we have.
Joel Cunningham
A: 

Here's a solution.

The second easiest solution after -r (which is to specify a From: header and separate it from the body by a newline like this

 $mail -s "Subject" [email protected]
 From: Joel <[email protected]>

 Hi!
 .

works in only a few mail versions, don't know what version redhat carries).

PS: Most versions of mail suck!

Vinko Vrsalovic
+2  A: 

http://www.mindspill.org/962 seems to have a solution.

Essentially:

echo "This is the main body of the mail" | mail -s "Subject of the Email" [email protected] -- -f [email protected]

Paolo Bergantino
+1  A: 

You can append sendmail options to the end of the mail command by first adding --. -f is the command on sendmail to set the from address. So you can do this:

mail [email protected] -- -f [email protected]

Gerald
This worked for me in RHEL5. Thanks!
shambleh
A: 

You can specify any extra header you may need with -a

$mail -s "Some random subject" -a "From: [email protected]" [email protected]
daniels
A: 

on CentOs5: -r [email protected]

FuN_ViT