Click to See Complete Forum and Search --> : perl/sendmail/mailfilter help requested


joesbox
03-04-2003, 01:00 AM
first the script

#!/usr/bin/perl

open (FILE, "</home/joe/mailfilter_logs/.mailfilter.log");
@log = <FILE>;
close (FILE);

foreach $log (@log) {
if ($log =~ "@freelotto.com"){
$counter++;
}
}
open (MAIL, "|/usr/sbin/sendmail -t") || die;

print MAIL "To: joes_box@cox.net\n From: mailfilter/n";
print MAIL "Subject: Deleted mail for bonnie";
print MAIL "$counter E-mails were deleted today. send a message to bonnie \n
letting her know that the program is working";
close (MAIL);

next the question. is there a way to have this program send me an email (or someone else one) without having a full running server. i don't have a running mail server going. i ran the program and this is the output:

[joe@joes-box cgi-bin]$ ./mailfilter*
sendmail: warning: My hostname joes-box is not a fully qualified name - set myhostname or mydomain in /etc/postfix/main.cf
postdrop: warning: My hostname joes-box is not a fully qualified name - set myhostname or mydomain in /etc/postfix/main.cf
[joe@joes-box cgi-bin]$

is there a way to have this use my isp's mailserver or maybe a mail client to send the mail?? or maybe this is for a different forum but is there a way to utilize my isp's mail server to launch mail from my box kinda like emulating a mail server for my intranet? hopefully i said everything write. i am new at this server thing.

joesbox
03-04-2003, 01:06 PM
*bump* for more views

spacedog
03-04-2003, 07:30 PM
hello,

ok im going to post code without the code tag, because i cant find it.

ok first there are many subtle problems with your code

your code below

first i assume your opening .mailfiletr.log for reading in which case you dont need '<' preceeding the name, as a matter of fact i havent seen anyone use '<' i think you want '>' or '>>' for writing and appending

second thing... I would assign @freelotto.com toa variable so you can do a
$var = '@freelotto.com';
if($log =~ /$var/)

third when writing to a mail pipe i suggest that you use
select(MAIL)
print <<MAIL;
To:
From:
CC:
Bcc:
Subject:

message
MAIL
select(STDOUT)

and fill in fields appropriatly.

the way you do it is fine, but you are missing some '\n' and have small syntax errors

#!/usr/bin/perl

open (FILE, "</home/joe/mailfilter_logs/.mailfilter.log");
@log = <FILE>;
close (FILE);

foreach $log (@log) {
if ($log =~ "@freelotto.com"){
$counter++;
}
}
open (MAIL, "|/usr/sbin/sendmail -t") || die;

print MAIL "To: joes_box@cox.net\n From: mailfilter/n";
print MAIL "Subject: Deleted mail for bonnie";
print MAIL "$counter E-mails were deleted today. send a message to bonnie \n
letting her know that the program is working";
close (MAIL);


as for your q's about servers and what not, i dont know much, but im sure you dont need your own mail server to send email through sendmail here is working code below

#!/usr/bin/perl

open (FILE, "/home/joe/mailfilter_logs/.mailfilter.log");
@log = <FILE>;
close (FILE);
$tmp = '@freelotto.com';
foreach $log (@log) {
if ($log =~ ){
$counter++;
}
}

open (MAIL, "|/usr/sbin/sendmail -t") || die;
print MAIL "To: joes_box@cox.net\nFrom: mailfilter\n";
print MAIL "Subject: Deleted mail for bonnie\n\n";
print MAIL "$counter E-mails were deleted today. send a message to bonnie \n
letting her know that the program is working";
close (MAIL);