Setting the from address field when sending command line e-mail

11/21/2007; 2:54 PM

To set the from address field when sending mail from the command line in linux use the following syntax:-

mail [standard mail options like subject etc.] send_email_to -- -f from_email_address

The trick is that after the e-mail you want to send it to you add -- (double dash) (space) (single dash) (NO space) f

Example:-

mail -s "Subject of the Email" recipent_address@example.com -- -f from_user@example.com
or
echo "This is the main body of the mail" | mail -s "Subject of the Email" recipent_address@example.com -- -f from_user@example.com

I've been trying to find out how to specify the from field in email for ages. Some people in forums even claimed that this cannot be done. (Hint: Never believe every word people write). Finally I found this post that outlined a quirk in the mail program that allows you to specify sendmail parameters in the command line. The man documentation in my RedHat Linux distribution doesn't even mention the possibility of specifying sendmail parameters.

Logon

Fill out the form below to logon to this site, or sign up below.

Username (email address):
Password:
I forgot my password; please send me a new one.
 

Signup

Fill out the form below to join as a member of this site.

Screen name:
Email address:
Password:
Repeat password:
Homepage (optional)