check if there's a mail host active before trying to send

This commit is contained in:
Nabeel Shahzad 2017-12-31 23:15:12 -06:00
parent 3984164689
commit 2f56baf7ff

View File

@ -6,6 +6,7 @@ use Log;
use Illuminate\Support\Facades\Mail;
use App\Events\UserRegistered;
use App\Events\UserStateChanged;
use App\Models\Enums\UserState;
/**
@ -27,6 +28,19 @@ class NotificationEventListener
);
}
/**
* @return bool
*/
protected function mailerActive()
{
if (empty(config('mail.host'))) {
Log::info('No mail host specified!');
return false;
}
return true;
}
/**
* Send an email when the user registered
* @param UserRegistered $event
@ -38,6 +52,10 @@ class NotificationEventListener
. UserState::label($event->user->state)
. ', sending active email');
if(!$this->mailerActive()) {
return;
}
# First send the admin a notification
$admin_email = setting('general.admin_email');
Log::info('Sending admin notification email to "'.$admin_email.'"');
@ -66,6 +84,10 @@ class NotificationEventListener
*/
public function onUserStateChange(UserStateChanged $event)
{
if (!$this->mailerActive()) {
return;
}
if ($event->old_state === UserState::PENDING) {
if ($event->user->state === UserState::ACTIVE)
{