X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fmsg_template%2Femail.pm;h=aebac74b7f160558af2d7e5fe27335b704d8d374;hp=753fd3d69252787a3ee883cc1ad875eeeebd4865;hb=3adb46fccf9f631e188ea5383bd147b340477639;hpb=4747bfbea3f4abb66d05a2bd1abed69e28a4aa3d diff --git a/FS/FS/msg_template/email.pm b/FS/FS/msg_template/email.pm index 753fd3d69..aebac74b7 100644 --- a/FS/FS/msg_template/email.pm +++ b/FS/FS/msg_template/email.pm @@ -16,7 +16,7 @@ use HTML::TreeBuilder; use Encode; # needed to send email -use FS::Misc qw( generate_email ); +use FS::Misc qw( generate_email email_sender_transport_or_error ); use FS::Conf; use Email::Sender::Simple qw( sendmail ); @@ -214,14 +214,14 @@ A L (or arrayref of them) to attach to the message. Set a string containing a comma-separated list. This list may contain: -- the text "invoice" indicating emails should only be sent to contact_email - addresses with the invoice_dest flag set -- the text "message" indicating emails should only be sent to contact_email - addresses with the message_dest flag set - - numbers representing classnum id values for email contact classes. - If any classnum are present, emails should only be sent to contact_email - addresses where contact_email.classnum contains one of these classes. - The classnum 0 also includes where contact_email.classnum IS NULL +- the text "invoice" indicating contacts with invoice_dest flag should + be included +- the text "message" indicating contacts with message_dest flag should + be included +- numbers representing classnum id values for email contact classes. + If any classnum are present, emails should only be sent to contact_email + addresses where contact_email.classnum contains one of these classes. + The classnum 0 also includes where contact_email.classnum IS NULL If neither 'invoice' nor 'message' has been specified, this method will behave as if 'invoice' had been selected @@ -529,6 +529,11 @@ sub send_prepared { my $self = shift; my $cust_msg = shift or die "cust_msg required"; + if ( $FS::Misc::DISABLE_ALL_NOTICES ) { + warn 'send_prepared() disabled by $FS::Misc::DISABLE_ALL_NOTICES' if $DEBUG; + return; + } + my $domain = 'example.com'; if ( $cust_msg->env_from =~ /\@([\w\.\-]+)/ ) { $domain = $1; @@ -538,39 +543,28 @@ sub send_prepared { # through Email::Address to make sure my @env_to = map { $_->address } Email::Address->parse($cust_msg->env_to); - my %smtp_opt = ( 'host' => $conf->config('smtpmachine'), - 'helo' => $domain ); - - my($port, $enc) = split('-', ($conf->config('smtp-encryption') || '25') ); - $smtp_opt{'port'} = $port; - - my $transport; - if ( defined($enc) && $enc eq 'starttls' ) { - $smtp_opt{$_} = $conf->config("smtp-$_") for qw(username password); - $transport = Email::Sender::Transport::SMTP::TLS->new( %smtp_opt ); - } else { - if ( $conf->exists('smtp-username') && $conf->exists('smtp-password') ) { - $smtp_opt{"sasl_$_"} = $conf->config("smtp-$_") for qw(username password); - } - $smtp_opt{'ssl'} = 1 if defined($enc) && $enc eq 'tls'; - $transport = Email::Sender::Transport::SMTP->new( %smtp_opt ); - } + my $transport = email_sender_transport_or_error($domain); - warn "$me sending message\n" if $DEBUG; - my $message = join("\n", $cust_msg->header, $cust_msg->body); - local $@; - eval { - sendmail( $message, { transport => $transport, - from => $cust_msg->env_from, - to => \@env_to }) - }; my $error = ''; - if(ref($@) and $@->isa('Email::Sender::Failure')) { - $error = $@->code.' ' if $@->code; - $error .= $@->message; - } - else { - $error = $@; + if ( ref($transport) ) { + + warn "$me sending message\n" if $DEBUG; + my $message = join("\n", $cust_msg->header, $cust_msg->body); + + local $SIG{__DIE__}; # don't want Mason __DIE__ handler active + local $@; + eval { sendmail( $message, { transport => $transport, + from => $cust_msg->env_from, + to => \@env_to }) + }; + if (ref($@) and $@->isa('Email::Sender::Failure')) { + $error = $@->code.' ' if $@->code; + $error .= $@->message; + } else { + $error = $@; + } + } else { + $error = $transport; } $cust_msg->set('error', $error);