diff --git a/app/Helpers/Mail/GmailTransport.php b/app/Helpers/Mail/GmailTransport.php index e13c6f07923c..0655c710cad8 100644 --- a/app/Helpers/Mail/GmailTransport.php +++ b/app/Helpers/Mail/GmailTransport.php @@ -64,23 +64,23 @@ class GmailTransport extends AbstractTransport $body->setRaw($this->base64_encode($bcc_list.$message->toString())); - try { + // try { $service->users_messages->send('me', $body, []); - } catch(\Google\Service\Exception $e) { - /* Need to slow down */ - if ($e->getCode() == '429') { - nlog("429 google - retrying "); + // } catch(\Google\Service\Exception $e) { + // /* Need to slow down */ + // if ($e->getCode() == '429') { + // nlog("429 google - retrying "); - sleep(rand(3,8)); + // sleep(rand(3,8)); - try { - $service->users_messages->send('me', $body, []); - } catch(\Google\Service\Exception $e) { + // try { + // $service->users_messages->send('me', $body, []); + // } catch(\Google\Service\Exception $e) { - } + // } - } - } + // } + // } } private function base64_encode($data) diff --git a/app/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index b1b1c94690eb..fad55c521f2c 100644 --- a/app/Jobs/Mail/NinjaMailerJob.php +++ b/app/Jobs/Mail/NinjaMailerJob.php @@ -164,7 +164,20 @@ class NinjaMailerJob implements ShouldQueue $this->cleanUpMailers(); $this->logMailError($e->getMessage(), $this->company->clients()->first()); return; - } catch (\Exception | \Google\Service\Exception $e) { + } + catch(\Google\Service\Exception $e){ + + if ($e->getCode() == '429') { + + $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); + + } + + } + catch (\Exception $e) { nlog("Mailer failed with {$e->getMessage()}"); $message = $e->getMessage(); @@ -221,8 +234,7 @@ class NinjaMailerJob implements ShouldQueue } /* Releasing immediately does not add in the backoff */ - sleep(rand(5, 10)); - + sleep(rand(2, 3)); $this->release($this->backoff()[$this->attempts() - 1]); } diff --git a/app/Services/Email/Email.php b/app/Services/Email/Email.php index e56091c909d5..d3edbf1aabfa 100644 --- a/app/Services/Email/Email.php +++ b/app/Services/Email/Email.php @@ -302,7 +302,21 @@ class Email implements ShouldQueue $this->cleanUpMailers(); $this->logMailError($e->getMessage(), $this->company->clients()->first()); return; - } catch (\Exception | \RuntimeException | \Google\Service\Exception $e) { + } + catch(\Google\Service\Exception $e){ + + if ($e->getCode() == '429') { + + $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); + $message = null; + } + + } + + catch (\Exception | \RuntimeException $e) { nlog("Mailer failed with {$e->getMessage()}"); $message = $e->getMessage(); diff --git a/app/Services/Email/EmailDefaults.php b/app/Services/Email/EmailDefaults.php index efcc85660683..718ac515dc6b 100644 --- a/app/Services/Email/EmailDefaults.php +++ b/app/Services/Email/EmailDefaults.php @@ -166,9 +166,9 @@ class EmailDefaults private function setBody(): self { - if (strlen($this->email->email_object->body) > 3) { + if (strlen($this->email->email_object->body ?? '') > 3) { // A Custom Message has been set in the email screen. - } elseif (strlen($this->email->email_object->settings?->{$this->email->email_object->email_template_body}) > 3) { + } elseif (strlen($this->email->email_object->settings?->{$this->email->email_object->email_template_body} ?? '') > 3) { // A body has been saved in the settings. $this->email->email_object->body = $this->email->email_object->settings?->{$this->email->email_object->email_template_body}; } else {