Coder Perfect

Specify the from user when sending email using the mail command


Is there a way to modify the from user when using the mail command to send email? I looked over the man page and couldn’t figure out how to accomplish it.

Redhat Linux 5 is the operating system we’re using.

Asked by Joel Cunningham

Solution #1

With -a, you can specify any additional headers you require.

$mail -s "Some random subject" -a "From: some@mail.tld" to@mail.tld

Answered by daniels

Solution #2

There appears to be a solution at


| mail -s “Subject of the Email” echo “This is the main body of the email” recipent from — -f

Answered by Paolo Bergantino

Solution #3

from@from.from mail -r -R -R -R from@from.

from-addr = from-addr -R stands for reply-to address.

The author has said that this flag is not supported by his version of mail. However, if you have a version that does, this will work perfectly.

Answered by bfabry

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

You might alternatively use the -a option to attach a file:

mail -s Subject -S -a path_to_attachement

Answered by G.J

Solution #5

None of these worked for me (Ubuntu 12.04), but after some trial and error, I was able to get:

echo 'my message blabla\nSecond line (optional of course)' | 
mail -s "Your message title"
-r 'Your full name<>'

(all on one line, no space between “-Sreplyto” and “-Sreplyto”)

This mail command came from:

apt-get install mailutils

Answered by Le Droid

Post is based on