Specify the from user when sending email using the mail command

When sending over SMTP, the mail man page advises to set the from variable, in this way (Tested on CentOS 6):

mail -s Subject -S [email protected] [email protected]

You could also attach a file using the -a option:

mail -s Subject -S [email protected] -a path_to_attachement [email protected]

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.


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

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

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]