Net::SMTP::Pipelining

Send email using ESMTP PIPELINING extension
Download

Net::SMTP::Pipelining Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Marc Beyer
  • Publisher web site:
  • http://search.cpan.org/~marcb/

Net::SMTP::Pipelining Tags


Net::SMTP::Pipelining Description

Send email using ESMTP PIPELINING extension Net::SMTP::Pipelining is a Perl module that implements the client side of the SMTP PIPELINING extension, as specified by RFC 2920 (http://tools.ietf.org/html/rfc2920). It extends the popular Net::SMTP module by subclassing it, you can use Net::SMTP::Pipelining objects as if they were regular Net::SMTP objects.SMTP PIPELINING increases the efficiency of sending messages over a high-latency network connection by reducing the number of command-response round-trips in client-server communication. To highlight the way regular SMTP differs from PIPELINING (and also the way of working with this module), here is a comparison ($s is the Net::SMTP or Net::SMTP::Pipelining object, $from the sender and $to the recipient):Regular SMTP using Net::SMTP: Perl code Client command Server response $s->mail($from); MAIL FROM: < fr@e.com > 250 Sender < fr@e.com > ok $s->to($to); RCPT TO: < to@e.com > 250 Recipient < to@e.com > ok $s->data(); DATA 354 Start mail,end with CRLF.CRLF $s->datasend("text"); text $s->dataend(); . 250 Message acceptedSending this message requires 4 round-trip exchanges between client and server. In comparison, Pipelined SMTP using Net::SMTP::Pipelining (when sending more than one message) only requires 2 round-trips for the last message and 1 round-trip for the others: Perl code Client command Server response $s->pipeline( { mail => $from, to => $to, data => "text", }); MAIL FROM: < fr@e.com > RCPT TO: < to@e.com > DATA 250 Sender < fr@e.com > ok 250 Recipient < to@e.com > ok 354 Start mail,end with CRLF.CRLF text . $s->pipeline( { mail => $from, to => $to, data => "text", }); MAIL FROM: < fr@e.com > RCPT TO: < to@e.com > DATA 250 Message sent 250 Sender < fr@e.com > ok 250 Recipient < to@e.com > ok 354 Start mail,end with CRLF.CRLF text . $s->pipe_flush(); 250 Message sentAs you can see, the pipeline call does not complete the sending of a single message. This is because a.) RFC 2920 mandates that DATA be the last command in a pipelined command group and b.) it is at this point uncertain whether another message will be sent afterwards. If another message is sent immediately afterwards, the MAIL, RCPT and DATA commands for this message can be included in the same command group as the text of the previous message, thus saving a round-trip. If you want to handle messages one after the other without mixing them in the same command group, you can call pipe_flush after every call to pipeline, that will work fine but be less efficient (the client-server communication then requires two round-trips per message instead of one).SYNOPSIS use Net::SMTP::Pipelining; my $smtp = Net::SMTP::Pipelining->new("localhost"); my $sender = q(sender@example.com); my (@successful,@failed); for my $address (q(s1@example.com), q(s2@example.com), q(s3@example.com)) { $smtp->pipeline({ mail => $sender, to => $address, data => qq(From: $sender This is a mail to $address), }) or push @failed,@{$smtp->pipe_rcpts_failed()}; push @successful, @{$smtp->pipe_rcpts_succeeded()}; } $smtp->pipe_flush() or push @failed,@{$smtp->pipe_rcpts_failed()}; push @successful, @{$smtp->pipe_rcpts_succeeded()}; print "Sent successfully to the following addresses: @successful "; warn "Failed sending to @failed " if scalar(@failed) >0; # More intricate error handling if (!$smtp->pipeline({ mail => $sender, to => $address, data => qq(From: $sender This is a mail to $address), })) { my $errors = $smtp->pipe_errors(); for my $e (@$errors) { print "An error occurred:, we said $e->{command} "; print "and the server responded $e->{code} $e->{message} " } } Requirements: · Perl


Net::SMTP::Pipelining Related Software