Sending mail as a differnt user

Rick Stevens rstevens at vitalstream.com
Wed Apr 6 21:56:10 UTC 2005


Tech Guy wrote:
> Hello Everyone,
> 
> I have a shell script that does some functions and finally sends the 
> report through the command "mail" in the script itself. The script has 
> to be run as root. The script works fine and we do receive emails with 
> the report.
> 
> But it sends the email as root. I want the mail to be sent as a 
> different user ( might not have account on that system) say 
> someuser at someadddress.com
> 
> I want to know if its possible to change the from address to someuser 
> other than root

I'm assuming the script is a simple shell script, so "mail" invokes the
standard "/bin/mail" program.  In that case, no, you can't spoof it,
because mail always sets the sender address as the user who ran it.

If, however, you modify the script so it uses sendmail instead, you can
spoof it--but only if the user running the script is root.  You can use
the "-f from-user at somedomain.com" option to sendmail:

	sendmail -f from-user at somedomain.com

sendmail will expect the mail content to be fed to its stdin as mail
would.  Note that this may cause messages such as:

     ...root set sender to from-user at somedomain.com using -f

to appear in /var/log/maillog.  Just wanted to warn you.
----------------------------------------------------------------------
- Rick Stevens, Senior Systems Engineer     rstevens at vitalstream.com -
- VitalStream, Inc.                       http://www.vitalstream.com -
-                                                                    -
-              Careful!  Ugly strikes 9 out of 10 people!            -
----------------------------------------------------------------------




More information about the Redhat-install-list mailing list