Unable to send mail from a particular address

user173141 asked:

Hi I have a script to send out email from a particular email address. Please correct it so that I can send mail using this script.

# script to send simple email
# Email To ?
# Email text/message
/bin/mail -s "SUBJECT" "$EMAIL" < $EMAILMESSAGE -- -f from_email_address

Still I am getting email from the hostname of the server rather than the email address I have mentioned (from_email_address). I am not trying to send spoof mail outside. It is for internal use only (for my backup server)

I answered:

Heirloom Mail, or mailx, the default mail command on Linux systems, uses the -r option for this, not -f.

       -r address
              Sets the From address. Overrides any from variable specified in
              environment or startup files.  Tilde escapes are disabled.  The
              -r address options are passed to the mail transfer agent unless
              SMTP is used.  This option exists for compatibility only; it is
              recommended to set the from variable directly instead.

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.