Subject: | IMPROVEMENT for sending email via finicky ISPs |
There are three reasons why Test::Reporter does not work for me. (Specifically, it does not work in its default configuration which is necessary for CPANPLUS to work.) The reasons are: 1) My ISP does not allow me to send email via some other MX server; 2) My ISP requires me to authenticate to send email; and 3) My ISP does not like the From: address that Test::Reporter chooses automatically for me. Attached is a patch that fixes all three. The new code looks for environment variables to trigger its work. Since RT doesn't let me attach more than one file, I will submit a POD patch separately.
*** Reporter.pm.orig Sun Nov 21 15:30:43 2004
--- Reporter.pm Sun Nov 21 15:32:23 2004
***************
*** 18,23 ****
--- 18,24 ----
use Config;
use Carp;
use Net::SMTP;
+ use Net::SMTP_auth;
use File::Temp;
use Test::Reporter::Mail::Util;
use Test::Reporter::Date::Format;
***************
*** 340,346 ****
warn __PACKAGE__, ": _send_smtp\n" if $self->debug();
my $helo = $self->_maildomain();
! my $from = $self->from();
my $via = $self->via();
my $debug = $self->debug();
my @recipients = @_;
--- 341,347 ----
warn __PACKAGE__, ": _send_smtp\n" if $self->debug();
my $helo = $self->_maildomain();
! my $from = $ENV{SMTPFROM} || $self->from();
my $via = $self->via();
my $debug = $self->debug();
my @recipients = @_;
***************
*** 365,384 ****
}
@recipients = @tmprecipients;
!
for my $mx (@{$self->{_mx}}) {
! $smtp = Net::SMTP->new((@{$self->{_mx}})[0], Hello => $helo,
! Timeout => $self->{_timeout}, Debug => $debug);
!
last if defined $smtp;
$fail++;
}
-
if ($fail == scalar @{$self->{_mx}}) {
$self->errstr(__PACKAGE__ . ': Unable to connect to any MX\'s');
return 0;
}
!
$via = ', via ' . $via if $via;
if (@recipients) {
--- 366,395 ----
}
@recipients = @tmprecipients;
! if ($ENV{SMTPSERVER} ne '') # added by Martin Thurn
! {
! unshift @{$self->{_mx}}, $ENV{SMTPSERVER};
! } # if
! my $thurnMXused;
for my $mx (@{$self->{_mx}}) {
! # print STDERR " DDD Test::Reporter::_send_smtp() trying MX ==$mx==\n";
! $smtp = Net::SMTP_auth->new($mx, Hello => $helo,
! Timeout => $self->{_timeout},
! Debug => $debug);
! $thurnMXused = $mx;
last if defined $smtp;
+ $thurnMXused = 'none';
$fail++;
}
if ($fail == scalar @{$self->{_mx}}) {
$self->errstr(__PACKAGE__ . ': Unable to connect to any MX\'s');
return 0;
}
! if ($ENV{SMTPPASSWORD} ne '') # added by Martin Thurn
! {
! # print STDERR " DDD login to $thurnMXused as $ENV{SMTPUSERNAME}...\n";
! $smtp->auth('LOGIN', $ENV{SMTPUSERNAME}, $ENV{SMTPPASSWORD});
! } # if
$via = ', via ' . $via if $via;
if (@recipients) {
***************
*** 386,391 ****
--- 397,404 ----
chomp $recipients;
chomp $recipients;
}
+ local $" = ',';
+ # print STDERR " DDD trying to send email from $from to @recipients...\n";
$success += $smtp->mail($from);
$success += $smtp->to($self->{_address});
***************
*** 404,418 ****
$success += $smtp->quit;
if (@recipients) {
$self->errstr(__PACKAGE__ .
! ": Unable to send test report to one or more recipients\n") if $success != 14;
}
else {
$self->errstr(__PACKAGE__ . ": Unable to send test report\n") if $success != 12;
}
-
return $self->errstr() ? 0 : 1;
! }
sub from {
my $self = shift;
--- 417,432 ----
$success += $smtp->quit;
if (@recipients) {
+ local $" = ',';
$self->errstr(__PACKAGE__ .
! ": Unable to send test report from $from to @recipients (success == $success)\n") if $success != 14;
}
else {
+ # print STDERR (" III in Test::Reporter::_send_report, MX is ==$thurnMXused==\n");
$self->errstr(__PACKAGE__ . ": Unable to send test report\n") if $success != 12;
}
return $self->errstr() ? 0 : 1;
! } # _send_smtp
sub from {
my $self = shift;