Jim Trocki wrote:

> On Wed, 19 Dec 2001, htabug wrote:
> 
> 
>>Hello
>>
>>In my current mon configuration, whenever the mail.alert script is called emails are 
>sent by the super user or root. Is there any way that a different user can be 
>specified to be the sender.
>>
> 
> 
> is there a particular reason why you're running mon as root? does it
> need to be running as root for any of your monitor scripts? i normally
> run it as user "mon", and all the emails come from "mon".
> 
> 
> 

Basically, I have a code fragment that replaces the stuff  from the open 
statement that pipes to sendmail with this: (this is actually from 
netpage.alert, so it's more compact, but you get the idea, hopefully:)

$smtp= Net::SMTP->new('mon.drew.edu');
$smtp->mail("${ALERT}_$opt_g/$opt_s");
$smtp->to($pageaddrs);
$smtp->data();
$smtp->datasend("Subject: $summary ($wday $mon $day $tm)");
$smtp->datasend("\n");
while (<STDIN>) {
         $smtp->datasend("$_");
}
$smtp->dataend();
$smtp->quit;


The $smtp->mail directive lets you stuff the sender field.  Stuffing it 
with the alert and service is much more useful on my pager (puts the 
important stuff first instead of me reading mon's email address first.)

I also like doing this because you're not piping to sendmail, which is 
also probably a bad idea, especially if mon is running as root.  Of 
course, Net::SMTP needs to be installed, which is not a problem with 
modern Perl setups and Linux distributions.

--Mike

Mike Richichi
Assistant Director of Academic Technology, Drew University
mailto:[EMAIL PROTECTED],  http://www.users.drew.edu/~mrichich/


Reply via email to