From 5ed27fe7478774ad67b173c95dd1c592c4a3bddc Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 27 May 2024 06:46:26 +1000 Subject: [PATCH] Catches for incorrectly configured mail servers --- app/Jobs/Mail/NinjaMailerJob.php | 13 ++++++++++--- app/Services/Email/Email.php | 7 ++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index fad55c521f2c..6f2ad06dcef0 100644 --- a/app/Jobs/Mail/NinjaMailerJob.php +++ b/app/Jobs/Mail/NinjaMailerJob.php @@ -152,24 +152,31 @@ class NinjaMailerJob implements ShouldQueue LightLogs::create(new EmailSuccess($this->nmo->company->company_key, $this->nmo->mailable->subject)) ->send(); - } catch (\Symfony\Component\Mime\Exception\RfcComplianceException $e) { + } + catch (\Symfony\Component\Mime\Exception\RfcComplianceException $e) { nlog("Mailer failed with a Logic Exception {$e->getMessage()}"); $this->fail(); $this->cleanUpMailers(); $this->logMailError($e->getMessage(), $this->company->clients()->first()); return; - } catch (\Symfony\Component\Mime\Exception\LogicException $e) { + } + catch (\Symfony\Component\Mime\Exception\LogicException $e) { nlog("Mailer failed with a Logic Exception {$e->getMessage()}"); $this->fail(); $this->cleanUpMailers(); $this->logMailError($e->getMessage(), $this->company->clients()->first()); return; } + catch(\Symfony\Component\Mailer\Transport\Dsn $e){ + nlog("Incorrectly configured mail server - setting to default mail driver."); + $this->nmo->settings->email_sending_method = 'default'; + return $this->setMailDriver(); + } catch(\Google\Service\Exception $e){ if ($e->getCode() == '429') { - $message = "Google rate limiting triggered, we are queueing based on GMail requirements."; + $message = "Google rate limiting triggered, we are queueing based on Gmail requirements."; $this->logMailError($message, $this->company->clients()->first()); sleep(rand(1, 2)); $this->release(900); diff --git a/app/Services/Email/Email.php b/app/Services/Email/Email.php index d3edbf1aabfa..aa6f084de6b1 100644 --- a/app/Services/Email/Email.php +++ b/app/Services/Email/Email.php @@ -303,11 +303,16 @@ class Email implements ShouldQueue $this->logMailError($e->getMessage(), $this->company->clients()->first()); return; } + catch(\Symfony\Component\Mailer\Transport\Dsn $e){ + nlog("Incorrectly configured mail server - setting to default mail driver."); + $this->email_object->settings->email_sending_method = 'default'; + return $this->setMailDriver(); + } catch(\Google\Service\Exception $e){ if ($e->getCode() == '429') { - $message = "Google rate limiting triggered, we are queueing based on GMail requirements."; + $message = "Google rate limiting triggered, we are queueing based on Gmail requirements."; $this->logMailError($message, $this->company->clients()->first()); sleep(rand(1, 2)); $this->release(900);