Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Mass Mailings with MIME::Lite

by thabenksta (Pilgrim)
on Jun 05, 2001 at 22:26 UTC ( [id://85929]=perlquestion: print w/replies, xml ) Need Help??

thabenksta has asked for the wisdom of the Perl Monks concerning the following question:

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 &lt\;$email&gt\;...<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';

Replies are listed 'Best First'.
Re: Mass Mailings with MIME::Lite
by Anonymous Monk on Jun 05, 2001 at 23:49 UTC
    If the close like on win32 doesn't close but assumes the close at the end of the program suffices, you have an open socket and an open log for each mail. Where the other 18 come from I don't know, but there could be qx and such internals to your Modules (too lazy to check).
Re: Mass Mailings with MIME::Lite
by Beatnik (Parson) on Jun 06, 2001 at 00:01 UTC
    Altho I deny all responsibility if this gets abused, you could look at Being lazy with MIME::Lite :)

    Greetz
    Beatnik
    ... Quidquid perl dictum sit, altum viditur.
Re: Mass Mailings with MIME::Lite
by John M. Dlugosz (Monsignor) on Jun 05, 2001 at 23:06 UTC
    Do you have on your platform a tool to see all the open handles in the system? Under Win32 there is handleex from sysinternals that is very handy for this.

    Programs like Purify, run on Perl, should also report the leak.

    —John

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://85929]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-19 04:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found