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.


In reply to About send mail by Net::SMTP and Postfix by pysome

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.