Имеется приложение ( http://www.bestpractical.com/rt/ ), которое отсылает наружу почту через Net::SMTP. Адреса получателей берутся как из базы учётных записей, так и вводятся вручную в Веб-формах. SMTP-сервер блокирует отправку на некоторые адреса. Проблема в том, что на клиентской стороне при этом всё зависает.
Вопрос: можно ли это обойти минимальными телодвижениями вокруг Net::SMTP?
Вот пример клиентской части:
Код | #!/usr/bin/perl -w # # Send email via SMTP using Perl. #
use strict;
#use Net::SMTP; use MIME::Entity;
die "Usage: t1 --arg1 val1 --arg2=val2 ...\n\t" if ($#ARGV < 0);
our %args; while (my $a = shift @ARGV) { if ($a =~ /^(.+)=(.+)$/) { $args{ucfirst lc $1} = $2; } elsif ($a =~ /^--(.+)=(.+)$/) { $args{ucfirst lc $1} = $2; } elsif ($a =~ /^--(.+)$/) { $args{ucfirst lc $1} = shift @ARGV or die "Missing parameter for $1\n"; } else { die "Invalid parameter: $a\n"; } }
print "Command line arguments:\n"; while (my ($k, $v) = each %args) { print "$k = $v\n"; } print "\n";
my $entity = MIME::Entity->build( Type =>"multipart/mixed", From => $args{'From'}, Bcc => $args{'Bcc'}, To => $args{'To'}, Subject => $args{'Subject'}, Precedence => 'bulk' );
$entity->attach( Data => $args{'Explanation'}."\n"); if ($args{'Attach'}) { $entity->attach(Data => $args{'Attach'}, Type => 'message/rfc822'); }
my @mailer_args = ('smtp'); push @mailer_args, ( Server => $args{'Server'} ); push @mailer_args, ( Debug => 1 ); unless ($entity->send(@mailer_args)) { print "Cannot send entity!\n"; } |
И вот что происходит во время сессии:
Код | # /home/evseev/mime2smtp.pl [email protected] [email protected] \ subject=test_perl_smtp "explanation=Testing message at 20:55" server=mail.company.ru
Command line arguments: Server = mail.company.ru Subject = test_perl_smtp Explanation = Testing message at 20:55 To = [email protected] From = [email protected]
Net::SMTP>>> Net::SMTP(2.29) Net::SMTP>>> Net::Cmd(2.26) Net::SMTP>>> Exporter(5.58) Net::SMTP>>> IO::Socket::INET(1.27) Net::SMTP>>> IO::Socket(1.28) Net::SMTP>>> IO::Handle(1.24) Net::SMTP=GLOB(0x852fe34)<<< 220 mail.company.ru ESMTP Postfix Net::SMTP=GLOB(0x852fe34)>>> EHLO localhost.localdomain Net::SMTP=GLOB(0x852fe34)<<< 250-mail.company.ru Net::SMTP=GLOB(0x852fe34)<<< 250-PIPELINING Net::SMTP=GLOB(0x852fe34)<<< 250-SIZE 20480000 Net::SMTP=GLOB(0x852fe34)<<< 250-ETRN Net::SMTP=GLOB(0x852fe34)<<< 250 8BITMIME Net::SMTP=GLOB(0x852fe34)>>> MAIL FROM:<[email protected]> Net::SMTP=GLOB(0x852fe34)<<< 250 Ok Net::SMTP=GLOB(0x852fe34)>>> RCPT TO:<[email protected]> Net::SMTP=GLOB(0x852fe34)<<< 554 <[email protected]>: Sender address rejected: Access denied Net::SMTP=GLOB(0x852fe34)>>> DATA Net::SMTP=GLOB(0x852fe34)<<< 554 Error: no valid recipients Net::SMTP=GLOB(0x852fe34)>>> Subject: test_perl_smtp Net::SMTP=GLOB(0x852fe34)>>> MIME-Version: 1.0 Net::SMTP=GLOB(0x852fe34)>>> X-Mailer: Mail::Mailer[v1.62] Net::SMTP[v2.29] Net::SMTP=GLOB(0x852fe34)>>> Sender: System Administrator <[email protected]> Net::SMTP=GLOB(0x852fe34)>>> Content-Type: multipart/mixed; boundary="----------=_1135965321-22875-0" Net::SMTP=GLOB(0x852fe34)>>> To: [email protected] Net::SMTP=GLOB(0x852fe34)>>> Content-Transfer-Encoding: binary Net::SMTP=GLOB(0x852fe34)>>> From: [email protected] Net::SMTP=GLOB(0x852fe34): Broken pipe at /usr/lib/perl5/vendor_perl/Mail/Mailer/smtp.pm line 80 Net::SMTP=GLOB(0x852fe34)>>> This is a multi-part message in MIME format... Net::SMTP=GLOB(0x852fe34): Timeout at /usr/lib/perl5/vendor_perl/Mail/Mailer/smtp.pm line 80 Net::SMTP=GLOB(0x852fe34)>>> ------------=_1135965321-22875-0 Net::SMTP=GLOB(0x852fe34): Timeout at /usr/lib/perl5/vendor_perl/Mail/Mailer/smtp.pm line 80 Net::SMTP=GLOB(0x852fe34)>>> Content-Type: text/plain Net::SMTP=GLOB(0x852fe34)>>> Content-Disposition: inline Net::SMTP=GLOB(0x852fe34)>>> Content-Transfer-Encoding: binary Net::SMTP=GLOB(0x852fe34): Timeout at /usr/lib/perl5/vendor_perl/Mail/Mailer/smtp.pm line 80 Net::SMTP=GLOB(0x852fe34): Timeout at /usr/lib/perl5/vendor_perl/Mail/Mailer/smtp.pm line 80 Net::SMTP=GLOB(0x852fe34)>>> Testing message at 20:55 Net::SMTP=GLOB(0x852fe34): Timeout at /usr/lib/perl5/vendor_perl/Mail/Mailer/smtp.pm line 80 Net::SMTP=GLOB(0x852fe34): Timeout at /usr/lib/perl5/vendor_perl/Mail/Mailer/smtp.pm line 80 Net::SMTP=GLOB(0x852fe34)>>> ------------=_1135965321-22875-0-- ...долго-долго ждём тайм-аута на сервере... Net::SMTP=GLOB(0x852fe34)>>> . Net::SMTP=GLOB(0x852fe34)<<< 221 Error: I can break rules, too. Goodbye. Net::SMTP=GLOB(0x852fe34)>>> QUIT # |
Пример слегка упрощён, поэтому сервер ругается на имя отправителя. В реальной жизни он может ругаться на имя получателя, и хочется сделать так, чтобы перловые библиотеки как-то это обрабатывали. |