[freeside-commits] branch FREESIDE_4_BRANCH updated. d3a5ab84183f540715c7a02964a10d065562ce41
Ivan Kohler
ivan at freeside.biz
Wed Sep 25 10:42:12 PDT 2019
The branch, FREESIDE_4_BRANCH has been updated
via d3a5ab84183f540715c7a02964a10d065562ce41 (commit)
from ae1138aab04dbb2b84830cee9807bcb4a46987a2 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit d3a5ab84183f540715c7a02964a10d065562ce41
Author: Ivan Kohler <ivan at freeside.biz>
Date: Wed Sep 25 10:40:47 2019 -0700
catch bad SMTP settings before they error out sending mail, RT#83775
diff --git a/FS/FS/Misc.pm b/FS/FS/Misc.pm
index a9d24c267..b787fb67f 100644
--- a/FS/FS/Misc.pm
+++ b/FS/FS/Misc.pm
@@ -280,9 +280,15 @@ sub send_email {
my($port, $enc) = split('-', ($conf->config('smtp-encryption') || '25') );
$smtp_opt{'port'} = $port;
+ my $error = '';
my $transport;
if ( defined($enc) && $enc eq 'starttls' ) {
- $smtp_opt{$_} = $conf->config("smtp-$_") for qw(username password);
+ foreach (qw(username password)) {
+ $smtp_opt{$_} = $conf->config("smtp-$_");
+ $error = "SMTP settings misconfiguration: ".
+ "STARTTLS enabled in smtp-encryption but smtp-$_ missing"
+ if ! length($smtp_opt{$_});
+ }
$transport = Email::Sender::Transport::SMTP::TLS->new( %smtp_opt );
} else {
if ( $conf->exists('smtp-username') && $conf->exists('smtp-password') ) {
@@ -300,19 +306,21 @@ sub send_email {
push @env_to, map { $_->address } Email::Address->parse($dest);
}
- local $SIG{__DIE__}; # don't want Mason __DIE__ handler active
- local $@; # just in case
- eval { sendmail($message, { transport => $transport,
- from => $from,
- to => \@env_to }) };
+ unless ( length($error) ) {
+
+ local $SIG{__DIE__}; # don't want Mason __DIE__ handler active
+ local $@; # just in case
+ eval { sendmail($message, { transport => $transport,
+ from => $from,
+ to => \@env_to }) };
+
+ if (ref($@) and $@->isa('Email::Sender::Failure')) {
+ $error = $@->code.' ' if $@->code;
+ $error .= $@->message;
+ } else {
+ $error = $@;
+ }
- my $error = '';
- if(ref($@) and $@->isa('Email::Sender::Failure')) {
- $error = $@->code.' ' if $@->code;
- $error .= $@->message;
- }
- else {
- $error = $@;
}
# Logging
@@ -332,6 +340,7 @@ sub send_email {
my $log_error = $cust_msg->insert;
warn "Error logging message: $log_error\n" if $log_error; # at least warn
}
+
$error;
}
-----------------------------------------------------------------------
Summary of changes:
FS/FS/Misc.pm | 35 ++++++++++++++++++++++-------------
1 file changed, 22 insertions(+), 13 deletions(-)
More information about the freeside-commits
mailing list