Specify the from user when sending email using the mail command

Solution 1:

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

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

Solution 2:

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]

Solution 3:

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.

Solution 4:

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]

Solution 5:

None of these worked for me (Ubuntu 12.04) but finally with trial & error I got:

echo 'my message blabla\nSecond line (optional of course)' | 
mail -s "Your message title"
-r 'Your full name<[email protected]>'
-Sreplyto="[email protected]"
[email protected][,[email protected]]

(all in one line, there is no space in "-Sreplyto")

I got this mail command from:

apt-get install mailutils