I'm working on mod_perl program that basically goes through a list of thousands of email addresses and sends an email using MIME::Lite and Net::SMTP to each address. The only problem is it breaks at about 200 emails. The only error I found was a kernel error like "Maximum number of open files 4096 reached". So I changed that number to 8000 and it made it to about 400 emails before it broke. Then I changed it to a ridiculously high number and it made it all the way through.
So my intial problem is solved, but why is the program opening almost 20 files for each email? The only files I open explicitly are the list of emails, HTML Header and Footer File, and a log file that is opened one time per email. Here is the basic idea of the program.
open (LIST, "<$listdir/$list");
my @list = <LIST>;
close(LIST);
print &headFoot("template.html", "header");
print "Sending Message...<br>\n";
foreach my $line (@list) {
chomp $line;
($email, $name) = split(/\,/, $line);
my $nameEmail = "$name <$email>";
my $msg = MIME::Lite->new(
From =>$from,
To =>$nameEmail,
'Reply-To' =>$replyto,
Subject =>$subject,
Type =>'text/plain',
Data =>$textmessage
);
$msg->send("smtp");
maillog($email, "text");
print("Sent to $name <\;$email>\;...<br>\n");
}
print "Done!";
print &headFoot($outTemp, "footer");
sub headFoot {
my $tempFile = $_[0];
my $request = $_[1];
my $header;
my $footer;
open (TEMP, "<$tempFile");
my @tempFile = <TEMP>;
close (TEMP);
my $template = join '', @tempFile;
($header, $footer) = split(/\@\@sentlist\@\@/, $template);
if ($request eq "header") {
return ($header);
} elsif ($request eq "footer") {
return ($footer);
}
}
sub maillog {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localti
+me(time);
open (LOG, ">>logs/maillog.dat");
$mon++;
$year += 1900;
print LOG "$mday/$mon/$year $hour:$sec:$min Sent to $_[0] as $_[1]
+\n";
close (LOG);
}
If anyone could give me a clue as to why so many files are being opened, or any other advice, I would appriciate it.
FYI - I am using MIME::Lite because in the original program I send out HTML and Multipart emails, and I tried using $msg->send("sendmail"); but i got the same result.
-
thabenksta
my $name = 'Ben Kittrell';
$name=~s/^(.+)\s(.).+$/\L$1$2/g;
my $nick = 'tha' . $name . 'sta';