[freeside-commits] branch master updated. 35ac5f08fc816cd7d79dc9a861652537061aed03

Ivan Kohler ivan at freeside.biz
Wed Sep 25 10:42:08 PDT 2019


The branch, master has been updated
       via  35ac5f08fc816cd7d79dc9a861652537061aed03 (commit)
      from  a284ef4c8d9d43db336a77db4c34996344cd5717 (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 35ac5f08fc816cd7d79dc9a861652537061aed03
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Wed Sep 25 10:40:43 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