text = $text; $this->title = $title; } /** * Execute the job. * * @return void */ public function handle() { // Configure mail driver according to Mailbox settings \MailHelper::setSystemMailDriver(); $recipients = User::nonDeleted() ->where('role', User::ROLE_ADMIN) ->where('invite_state', User::INVITE_STATE_ACTIVATED) ->pluck('email') ->toArray(); $extra = \MailHelper::sanitizeEmails(\Option::get('alert_recipients')); if ($extra) { $recipients = array_unique(array_merge($recipients, $extra)); } foreach ($recipients as $recipient) { $exception = null; try { Mail::to([['name' => '', 'email' => $recipient]]) ->send(new Alert($this->text, $this->title)); } catch (\Exception $e) { // We come here in case SMTP server unavailable for example activity() ->withProperties([ 'error' => $e->getMessage().'; File: '.$e->getFile().' ('.$e->getLine().')', ]) ->useLog(\App\ActivityLog::NAME_EMAILS_SENDING) ->log(\App\ActivityLog::DESCRIPTION_EMAILS_SENDING_ERROR_ALERT); $exception = $e; } $status_message = ''; if ($exception) { $status = SendLog::STATUS_SEND_ERROR; $status_message = $exception->getMessage(); } else { $failures = Mail::failures(); if (!empty($failures)) { $status = SendLog::STATUS_SEND_ERROR; } else { $status = SendLog::STATUS_ACCEPTED; } } SendLog::log(null, null, $recipient, SendLog::MAIL_TYPE_ALERT, $status, null, null, $status_message); } if ($exception) { throw $exception; } } }