Sending a message from the Unix command line using mail TO_ADDR
results in an email from $USER@$HOSTNAME
. Is there a way to change the \"From:\" ad
In my version of mail ( Debian linux 4.0 ) the following options work for controlling the source / reply addresses
so the following sequence
export REPLYTO=cms-replies@example.com
mail -aFrom:cms-sends@example.com -s 'Testing'
The result, in my mail clients, is a mail from cms-sends@example.com, which any replies to will default to cms-replies@example.com
NB: Mac OS users: you don't have -a , but you do have $REPLYTO
NB(2): CentOS users, many commenters have added that you need to use -r
not -a
NB(3): This answer is at least ten years old(1), please bear that in mind when you're coming in from Google.
Plus it's good to use -F option
to specify Name of sender.
Something like this:
mail -s "$SUBJECT" $MAILTO -- -F $MAILFROM -f ${MAILFROM}@somedomain.com
Or just look at available options: http://www.courier-mta.org/sendmail.html
The answers provided before didn't work for me on CentOS5. I installed mutt. It has a lot of options. With mutt you do this this way:
export EMAIL=myfrom@example.com
export REPLYTO=myreplyto@example.com
mutt -s Testing chris@example.org
this worked for me
echo "hi root"|mail -rsawrub@testingdomain.org -s'testinggg' root
None of the above solutions are working for me...
#!/bin/bash
# Message
echo "My message" > message.txt
# Mail
subject="Test"
mail_header="From: John Smith <john.smith@example.com>"
recipients="recipient@example.com"
#######################################################################
cat message.txt | mail -s "$subject" -a "$mail_header" -t "$recipients"
It's also possible to set both the From name and from address using something like:
echo test | mail -s "test" example@example.com -- -F'Some Name<example2@example.com>' -t
For some reason passing -F'Some Name'
and -fexample2@example.com
doesn't work, but passing in the -t
to sendmail works and is "easy".