From 6b1506ee3970ed5ee7621dfb2dd504947637254f Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Mon, 4 Jan 2021 13:14:11 +0000 Subject: [PATCH] Remove use of ignoreException() from SMTP settings form. --- CRM/Admin/Form/Setting/Smtp.php | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/CRM/Admin/Form/Setting/Smtp.php b/CRM/Admin/Form/Setting/Smtp.php index 79e0da4f77..83ec40083a 100644 --- a/CRM/Admin/Form/Setting/Smtp.php +++ b/CRM/Admin/Form/Setting/Smtp.php @@ -171,21 +171,24 @@ class CRM_Admin_Form_Setting_Smtp extends CRM_Admin_Form_Setting { $mailer = CRM_Utils_Mail::_createMailer($mailerName, $params); - $errorScope = CRM_Core_TemporaryErrorScope::ignoreException(); - $result = $mailer->send($toEmail, $headers, $message); - unset($errorScope); - if (defined('CIVICRM_MAIL_LOG') && defined('CIVICRM_MAIL_LOG_AND_SEND')) { - $testMailStatusMsg .= '
' . ts('You have defined CIVICRM_MAIL_LOG_AND_SEND - mail will be logged.') . '

'; - } - if (defined('CIVICRM_MAIL_LOG') && !defined('CIVICRM_MAIL_LOG_AND_SEND')) { - CRM_Core_Session::setStatus($testMailStatusMsg . ts('You have defined CIVICRM_MAIL_LOG - no mail will be sent. Your %1 settings have not been tested.', [1 => strtoupper($mailerName)]), ts("Mail not sent"), "warning"); - } - elseif (!is_a($result, 'PEAR_Error')) { - CRM_Core_Session::setStatus($testMailStatusMsg . ts('Your %1 settings are correct. A test email has been sent to your email address.', [1 => strtoupper($mailerName)]), ts("Mail Sent"), "success"); + try { + $errorScope = CRM_Core_TemporaryErrorScope::useException(); + $mailer->send($toEmail, $headers, $message); + if (defined('CIVICRM_MAIL_LOG') && defined('CIVICRM_MAIL_LOG_AND_SEND')) { + $testMailStatusMsg .= '
' . ts('You have defined CIVICRM_MAIL_LOG_AND_SEND - mail will be logged.') . '

'; + } + if (defined('CIVICRM_MAIL_LOG') && !defined('CIVICRM_MAIL_LOG_AND_SEND')) { + CRM_Core_Session::setStatus($testMailStatusMsg . ts('You have defined CIVICRM_MAIL_LOG - no mail will be sent. Your %1 settings have not been tested.', [1 => strtoupper($mailerName)]), ts("Mail not sent"), "warning"); + } + else { + CRM_Core_Session::setStatus($testMailStatusMsg . ts('Your %1 settings are correct. A test email has been sent to your email address.', [1 => strtoupper($mailerName)]), ts("Mail Sent"), "success"); + } } - else { - $message = CRM_Utils_Mail::errorMessage($mailer, $result); - CRM_Core_Session::setStatus($testMailStatusMsg . ts('Oops. Your %1 settings are incorrect. No test mail has been sent.', [1 => strtoupper($mailerName)]) . $message, ts("Mail Not Sent"), "error"); + catch (Exception $e) { + $result = $e; + Civi::log()->error($e->getMessage()); + $errorMessage = CRM_Utils_Mail::errorMessage($mailer, $result); + CRM_Core_Session::setStatus($testMailStatusMsg . ts('Oops. Your %1 settings are incorrect. No test mail has been sent.', [1 => strtoupper($mailerName)]) . $errorMessage, ts("Mail Not Sent"), "error"); } } } -- 2.25.1