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';

In reply to Mass Mailings with MIME::Lite by thabenksta

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.