check if there's a mail host active before trying to send
This commit is contained in:
parent
3984164689
commit
2f56baf7ff
@ -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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user