http://qs321.pair.com?node_id=636701

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

Hi Monks, I came cross a strange problem when ran a script to send email.Pls help me!
I write a class M.pm :
package M; use DBI; use Net::SMTP; sub new { my $class = shift; bless($self, $class); $self->{DBH} = DBI->connect("xxxx","xxxx","xxxx") or die "can't c +onnect\n"; ### (1) $self->{SMTP} = Net::SMTP->new("mail.test.com"); return $self; } sub get_list { my $self = shift; my @list; my $sth = $self->{DBH}->prepare(qq{select email from uses}); my ($email); $sth->bind_columns(undef, \$email); push @list,$email while ($sth->fetch); $sth->finish; $self->{DBH}->disconnect; return \@list; } sub send_mail { my($self,$to) = @_; ### (2) $self->{SMTP} = Net::SMTP->new("mail.test.com"); + $self->{SMTP}->mail("ttsdf@sdf.com"); $self->{SMTP}->to($to); $self->{SMTP}->data(); $self->{SMTP}->datasend('From: ttsdf@sdf.com'); $self->{SMTP}->datasend("\n"); $self->{SMTP}->datasend('To: '.$to); $self->{SMTP}->datasend("\n"); $self->{SMTP}->datasend('Content-type:text/html;Charset=utf8'); $self->{SMTP}->datasend("\n"); $self->{SMTP}->datasend("Subject: $title"); $self->{SMTP}->datasend("\n\n"); $self->{SMTP}->datasend("hello\n"); $self->{SMTP}->dataend(); ### (3) $self->{SMTP}->quit; } sub over { my $self = shift; ### (4) $self->{SMTP}->quit; } 1;
Then i call the class with a script s.pl
use M; my $m = new M(); for my $adr (@$m->get_list) { $m->send_mail($adr); sleep(1) ; #sleep one second } $m->over;
My user list is about 100,000. I have tried two methods to perform my mission.
Method One:
  I remove the comment (2) and (3) in Package M. That is to say, i connect SMTP every time for every user-list.
  This can work,but it so time-consumed.
Method Two:
  I remove the comment(1) and (4) in package M. That is to say,I connect SMTP server only once.Then i sent list
  over and over,at the end,i closed the smpt connection.
  But this method can't work normally! It broke about only sent 10,000 lists or later. 
  
How to fix this issues? Do i need do some special configuration to Postfix? Or how do a persistent connection to Postfix?

Thanks in advance.