diff --git a/app/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index 987e79f65716..0c3fd1928772 100644 --- a/app/Jobs/Mail/NinjaMailerJob.php +++ b/app/Jobs/Mail/NinjaMailerJob.php @@ -227,6 +227,10 @@ class NinjaMailerJob implements ShouldQueue if(Ninja::isHosted() && strpos($this->nmo->to_user->email, '@example.com') !== false) return true; + /* GMail users are uncapped */ + if(Ninja::isHosted() && $this->nmo->settings->email_sending_method == 'gmail') + return false; + /* On the hosted platform, if the user is over the email quotas, we do not send the email. */ if(Ninja::isHosted() && $this->company->account->emailQuotaExceeded()) return true; diff --git a/app/Models/Account.php b/app/Models/Account.php index 1e6119078e70..ae563d050eed 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -369,21 +369,26 @@ class Account extends BaseModel if(is_null(Cache::get($this->key))) return false; - if(Cache::get($this->key) > $this->getDailyEmailLimit()) { + try { + if(Cache::get($this->key) > $this->getDailyEmailLimit()) { - if(is_null(Cache::get("throttle_notified:{$this->key}"))) { + if(is_null(Cache::get("throttle_notified:{$this->key}"))) { - $nmo = new NinjaMailerObject; - $nmo->mailable = new EmailQuotaExceeded($this->companies()->first()); - $nmo->company = $this->companies()->first(); - $nmo->settings = $this->companies()->first()->settings; - $nmo->to_user = $this->companies()->first()->owner(); - NinjaMailerJob::dispatch($nmo); + $nmo = new NinjaMailerObject; + $nmo->mailable = new EmailQuotaExceeded($this->companies()->first()); + $nmo->company = $this->companies()->first(); + $nmo->settings = $this->companies()->first()->settings; + $nmo->to_user = $this->companies()->first()->owner(); + NinjaMailerJob::dispatch($nmo); - Cache::put("throttle_notified:{$this->key}", true, 60 * 24); + Cache::put("throttle_notified:{$this->key}", true, 60 * 24); + } + + return true; } - - return true; + } + catch(\Exception $e){ + \Sentry\captureMessage("I encountered an error with email quotas - defaulting to SEND"); } return false;