check if there's a mail host active before trying to send
This commit is contained in:
@@ -6,6 +6,7 @@ use Log;
|
|||||||
use Illuminate\Support\Facades\Mail;
|
use Illuminate\Support\Facades\Mail;
|
||||||
|
|
||||||
use App\Events\UserRegistered;
|
use App\Events\UserRegistered;
|
||||||
|
use App\Events\UserStateChanged;
|
||||||
use App\Models\Enums\UserState;
|
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
|
* Send an email when the user registered
|
||||||
* @param UserRegistered $event
|
* @param UserRegistered $event
|
||||||
@@ -38,6 +52,10 @@ class NotificationEventListener
|
|||||||
. UserState::label($event->user->state)
|
. UserState::label($event->user->state)
|
||||||
. ', sending active email');
|
. ', sending active email');
|
||||||
|
|
||||||
|
if(!$this->mailerActive()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
# First send the admin a notification
|
# First send the admin a notification
|
||||||
$admin_email = setting('general.admin_email');
|
$admin_email = setting('general.admin_email');
|
||||||
Log::info('Sending admin notification email to "'.$admin_email.'"');
|
Log::info('Sending admin notification email to "'.$admin_email.'"');
|
||||||
@@ -66,6 +84,10 @@ class NotificationEventListener
|
|||||||
*/
|
*/
|
||||||
public function onUserStateChange(UserStateChanged $event)
|
public function onUserStateChange(UserStateChanged $event)
|
||||||
{
|
{
|
||||||
|
if (!$this->mailerActive()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ($event->old_state === UserState::PENDING) {
|
if ($event->old_state === UserState::PENDING) {
|
||||||
if ($event->user->state === UserState::ACTIVE)
|
if ($event->user->state === UserState::ACTIVE)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user