From a31cd1c407379485a548f23811b745f3987f4c3b Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 29 Apr 2024 10:07:53 +1000 Subject: [PATCH] Gracefully fall back when smtp configuration is incorrect --- app/Jobs/Mail/NinjaMailerJob.php | 12 +++++++++++- app/Services/Email/Email.php | 10 +++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index 3f33759a0b17..22a9069c5ac8 100644 --- a/app/Jobs/Mail/NinjaMailerJob.php +++ b/app/Jobs/Mail/NinjaMailerJob.php @@ -363,7 +363,7 @@ nlog("nn"); return $this; } - private function configureSmtpMailer(): void + private function configureSmtpMailer() { $company = $this->company; @@ -376,6 +376,16 @@ nlog("nn"); $smtp_local_domain = strlen($company->smtp_local_domain) > 2 ? $company->smtp_local_domain : null; $smtp_verify_peer = $company->smtp_verify_peer ?? true; + if(strlen($smtp_host ?? '') <= 1 || + strlen($smtp_username ?? '') <= 1 || + strlen($smtp_password ?? '') <= 1 + ) + { + $this->nmo->settings->email_sending_method = 'default'; + return $this->setMailDriver(); + } + + config([ 'mail.mailers.smtp' => [ 'transport' => 'smtp', diff --git a/app/Services/Email/Email.php b/app/Services/Email/Email.php index 71369529727d..661b8aef52c4 100644 --- a/app/Services/Email/Email.php +++ b/app/Services/Email/Email.php @@ -589,7 +589,7 @@ $this->entityEmailFailed($message); return $this; } - private function configureSmtpMailer(): void + private function configureSmtpMailer() { $company = $this->company; @@ -602,6 +602,14 @@ $this->entityEmailFailed($message); $smtp_local_domain = strlen($company->smtp_local_domain) > 2 ? $company->smtp_local_domain : null; $smtp_verify_peer = $company->smtp_verify_peer ?? true; + if(strlen($smtp_host ?? '') <= 1 || + strlen($smtp_username ?? '') <= 1 || + strlen($smtp_password ?? '') <= 1 + ) { + $this->email_object->settings->email_sending_method = 'default'; + return $this->setMailDriver(); + } + config([ 'mail.mailers.smtp' => [ 'transport' => 'smtp',