Problem
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 http://www.mindspill.org/962.
Essentially:
| mail -s “Subject of the Email” echo “This is the main body of the email” recipent address@example.com from user@example.com — -f
Answered by Paolo Bergantino
Solution #3
from@from.from mail -r -R from@from.com -R from@from.com -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 from=sender@example.com recipient@example.com
You might alternatively use the -a option to attach a file:
mail -s Subject -S from=sender@example.com -a path_to_attachement recipient@example.com
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<yourSenderAdress@yourDomain.abc>'
-Sreplyto="yourReplyAdressIfDifferent@domain.abc"
destinatorEmail@destDomain.abc[,otherDestinator@otherDomain.abc]
(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 https://stackoverflow.com/questions/119390/specify-the-from-user-when-sending-email-using-the-mail-command