diff --git a/app/Listeners/NotificationEventListener.php b/app/Listeners/NotificationEventListener.php index 63d9b676..527068a1 100644 --- a/app/Listeners/NotificationEventListener.php +++ b/app/Listeners/NotificationEventListener.php @@ -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) {