From f7e1a877f69a8a144fc2da7a422c4e3f728321cb Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 20 Dec 2004 10:14:04 +0000 Subject: [PATCH] better error messages on email errors --- FS/FS/Misc.pm | 78 +++++++++++++++++++++++++++++++++++++++---- FS/FS/cust_main.pm | 1 + httemplate/view/cust_bill.cgi | 2 +- 3 files changed, 73 insertions(+), 8 deletions(-) diff --git a/FS/FS/Misc.pm b/FS/FS/Misc.pm index efad2dfd6..df9717068 100644 --- a/FS/FS/Misc.pm +++ b/FS/FS/Misc.pm @@ -78,16 +78,80 @@ sub send_email { my $smtpmachine = $conf->config('smtpmachine'); $!=0; - my $rv = $message->smtpsend( 'Host' => $smtpmachine ) - or $message->smtpsend( Host => $smtpmachine, Debug => 1 ); + $message->mysmtpsend( 'Host' => $smtpmachine, + 'MailFrom' => $options{'from'}, + ); - if ($rv) { #smtpsend returns a list of addresses, not true/false - return ''; - } else { - return "can't send email to $to via server $smtpmachine with SMTP: $!"; - } +} + +package Mail::Internet; + +use Mail::Address; +use Net::SMTP; + +sub Mail::Internet::mysmtpsend { + my $src = shift; + my %opt = @_; + my $host = $opt{Host}; + my $envelope = $opt{MailFrom}; + my $noquit = 0; + my $smtp; + my @hello = defined $opt{Hello} ? (Hello => $opt{Hello}) : (); + + push(@hello, 'Port', $opt{'Port'}) + if exists $opt{'Port'}; + + push(@hello, 'Debug', $opt{'Debug'}) + if exists $opt{'Debug'}; + + if(ref($host) && UNIVERSAL::isa($host,'Net::SMTP')) { + $smtp = $host; + $noquit = 1; + } + else { + #local $SIG{__DIE__}; + #$smtp = eval { Net::SMTP->new($host, @hello) }; + $smtp = new Net::SMTP $host, @hello; + } + + unless ( defined($smtp) ) { + my $err = $!; + $err =~ s/Invalid argument/Unknown host/; + return "can't connect to $host: $err" + } + + my $hdr = $src->head->dup; + + _prephdr($hdr); + + # Who is it to + + my @rcpt = map { ref($_) ? @$_ : $_ } grep { defined } @opt{'To','Cc','Bcc'}; + @rcpt = map { $hdr->get($_) } qw(To Cc Bcc) + unless @rcpt; + my @addr = map($_->address, Mail::Address->parse(@rcpt)); + + return 'No valid destination addresses found!' + unless(@addr); + + $hdr->delete('Bcc'); # Remove blind Cc's + + # Send it + + my $ok = $smtp->mail( $envelope ) && + $smtp->to(@addr) && + $smtp->data(join("", @{$hdr->header},"\n",@{$src->body})); + + if ( $ok ) { + $smtp->quit + unless $noquit; + return ''; + } else { + return $smtp->code. ' '. $smtp->message; + } } +package FS::Misc; =head1 BUGS diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 34ca9d4af..c42d22239 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -1582,6 +1582,7 @@ sub collect { my $error; { local $realtime_bop_decline_quiet = 1 if $options{'quiet'}; + local $SIG{__DIE__}; # don't want Mason __DIE__ handler active $error = eval $part_bill_event->eventcode; } diff --git a/httemplate/view/cust_bill.cgi b/httemplate/view/cust_bill.cgi index 34f533196..ca0612d09 100755 --- a/httemplate/view/cust_bill.cgi +++ b/httemplate/view/cust_bill.cgi @@ -47,7 +47,7 @@ unless ( $templatename ) { sort { $a->_date <=> $b->_date } $cust_bill->cust_bill_event ) { my $status = $cust_bill_event->status; - $status .= ': '. $cust_bill_event->statustext + $status .= ': '. encode_entities($cust_bill_event->statustext) if $cust_bill_event->statustext; my $part_bill_event = $cust_bill_event->part_bill_event; print ''. $part_bill_event->event; -- 2.11.0