1

I am trying to send an email by specifying the from option using mail.

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

Whenever I try the above command I always get error as-

mail: Options MUST PRECEDE persons

And I didn't get any emails. Why is it so?

And I am running SunOS

bash-3.00$ uname -a
SunOS lvsaishdc3in0001 5.10 Generic_142901-02 i86pc i386 i86pc
AKIWEB
  • 19,008
  • 67
  • 180
  • 294

1 Answers1

2

EDIT Your title indicates one thing, now I see you want to pass in who the sender is. Per quote from man page below, -f doesn't mean from.

Why do you need to do this, your mail client and sendmail will properly set your 'from' header? (and please answer this by editing your question, not as a comment below :-) ).

end edit

The reason you're getting the error message that you do get is that for almost all Unix commands (including mail) using -- indicates to the program (mail) 'END OF OPTIONS'.

So your -f will not be processed as you expect. Why don't you do

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

???

For the two mail(*) programs I could find man-pages for online, they both have similar use for the -f option:

 -f [file]       Read messages from file instead of  mailbox.
                     If no file is specified, the mbox is used.

So is that what you intend? And, to put it another way, your use of -f user@example.com doesn't seem to make sense unless you have mailbox files named like that.

IHTH

shellter
  • 36,525
  • 7
  • 83
  • 90