Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

About send mail by Net::SMTP and Postfix

by pysome (Scribe)
on Sep 03, 2007 at 09:30 UTC ( [id://636701]=perlquestion: print w/replies, xml ) Need Help??

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.

Replies are listed 'Best First'.
Re: About send mail by Net::SMTP and Postfix
by Corion (Patriarch) on Sep 03, 2007 at 10:23 UTC

    Have you looked at Mail::Bulkmail?

    To me it seems as if your mail server does not want "too many" mails sent within one connection, which may waste too many resources.

      The module maybe can't fit my need.Because my email is customized for every user list. Thanks
Re: About send mail by Net::SMTP and Postfix
by pysome (Scribe) on Sep 06, 2007 at 02:30 UTC
    need more help

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-04-19 02:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found