diff --git a/app/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index 6e54dc7d5db2..f421667a31a4 100644 --- a/app/Jobs/Mail/NinjaMailerJob.php +++ b/app/Jobs/Mail/NinjaMailerJob.php @@ -145,7 +145,8 @@ class NinjaMailerJob implements ShouldQueue ->send($mailable); /* Count the amount of emails sent across all the users accounts */ - Cache::increment("email_quota".$this->company->account->key); + + $this->incrementEmailCounter(); LightLogs::create(new EmailSuccess($this->nmo->company->company_key, $this->nmo->mailable->subject)) ->send(); @@ -221,6 +222,12 @@ class NinjaMailerJob implements ShouldQueue $this->cleanUpMailers(); } + private function incrementEmailCounter(): void + { + if(in_array($this->mailer, ['default','mailgun'])) + Cache::increment("email_quota".$this->company->account->key); + + } /** * Entity notification when an email fails to send * diff --git a/app/Services/Email/Email.php b/app/Services/Email/Email.php index 80cc5b0e9a40..f47189009b3f 100644 --- a/app/Services/Email/Email.php +++ b/app/Services/Email/Email.php @@ -244,6 +244,12 @@ class Email implements ShouldQueue return $this; } + private function incrementEmailCounter(): void + { + if(in_array($this->mailer, ['default','mailgun'])) + Cache::increment("email_quota".$this->company->account->key); + } + /** * Attempts to send the email * @@ -270,7 +276,7 @@ class Email implements ShouldQueue $mailer->send($this->mailable); - Cache::increment("email_quota".$this->company->account->key); + $this->incrementEmailCounter(); LightLogs::create(new EmailSuccess($this->company->company_key, $this->mailable->subject)) ->send();