diff --git a/app/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index e0a78a829de2..ce94381dc4bd 100644 --- a/app/Jobs/Mail/NinjaMailerJob.php +++ b/app/Jobs/Mail/NinjaMailerJob.php @@ -40,6 +40,7 @@ use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Lang; use Illuminate\Support\Facades\Mail; use Turbo124\Beacon\Facades\LightLogs; +use Illuminate\Support\Facades\Cache; /*Multi Mailer implemented*/ @@ -110,11 +111,10 @@ class NinjaMailerJob implements ShouldQueue LightLogs::create(new EmailSuccess($this->nmo->company->company_key)) ->batch(); + /* Count the amount of emails sent across all the users accounts */ + Cache::increment($this->company->account->key); + } catch (\Exception $e) { - - // if($e instanceof GuzzleHttp\Exception\ClientException){ - - // } nlog("error failed with {$e->getMessage()}"); @@ -227,6 +227,10 @@ class NinjaMailerJob implements ShouldQueue if(Ninja::isHosted() && strpos($this->nmo->to_user->email, '@example.com') !== false) return true; + /* On the hosted platform, if the user is over the email quotas, we do not send the email. */ + //if(Ninja::isHosted()) + + return false; } @@ -254,4 +258,5 @@ class NinjaMailerJob implements ShouldQueue LightLogs::create($job_failure) ->batch(); } -} + +} \ No newline at end of file diff --git a/database/migrations/2021_08_07_092524_add_email_quota_to_accounts_table.php b/database/migrations/2021_08_07_092524_add_email_quota_to_accounts_table.php new file mode 100644 index 000000000000..3b78b3c4c957 --- /dev/null +++ b/database/migrations/2021_08_07_092524_add_email_quota_to_accounts_table.php @@ -0,0 +1,30 @@ +unsignedInteger('email_quota')->nullable()->default(300); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + + } +}