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.
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.
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.
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!
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]
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]
You can specify any extra header you may need with -a
$mail -s "Some random subject" -a "From: [email protected]" [email protected]