freeside/FS/FS Misc.pm,1.3,1.4 cust_main.pm,1.166,1.167
ivan
ivan at pouncequick.420.am
Mon Dec 20 02:13:43 PST 2004
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory pouncequick:/tmp/cvs-serv9600/FS/FS
Modified Files:
Misc.pm cust_main.pm
Log Message:
better error messages on email errors
Index: cust_main.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_main.pm,v
retrieving revision 1.166
retrieving revision 1.167
diff -u -d -r1.166 -r1.167
--- cust_main.pm 12 Dec 2004 08:34:36 -0000 1.166
+++ cust_main.pm 20 Dec 2004 10:13:37 -0000 1.167
@@ -1582,6 +1582,7 @@
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;
}
Index: Misc.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Misc.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- Misc.pm 11 Jun 2003 20:27:18 -0000 1.3
+++ Misc.pm 20 Dec 2004 10:13:37 -0000 1.4
@@ -78,16 +78,80 @@
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
More information about the freeside-commits
mailing list