From adaef2d3413a1ca9392667d72bb95c6fabd01685 Mon Sep 17 00:00:00 2001 From: peaklabs-dev <122374094+peaklabs-dev@users.noreply.github.com> Date: Mon, 9 Dec 2024 17:37:15 +0100 Subject: [PATCH] feat: use new table or instance settings for email --- app/Notifications/Channels/EmailChannel.php | 33 ++++++++++++--------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/app/Notifications/Channels/EmailChannel.php b/app/Notifications/Channels/EmailChannel.php index 5394f6106..0985f4393 100644 --- a/app/Notifications/Channels/EmailChannel.php +++ b/app/Notifications/Channels/EmailChannel.php @@ -13,7 +13,7 @@ class EmailChannel { try { $this->bootConfigs($notifiable); - $recipients = $notifiable->getRecepients($notification); + $recipients = $notifiable->getRecipients($notification); if (count($recipients) === 0) { throw new Exception('No email recipients found'); } @@ -46,7 +46,9 @@ class EmailChannel private function bootConfigs($notifiable): void { - if (data_get($notifiable, 'use_instance_email_settings')) { + $emailSettings = $notifiable->emailNotificationSettings; + + if ($emailSettings->use_instance_email_settings) { $type = set_transanctional_email_settings(); if (! $type) { throw new Exception('No email settings found.'); @@ -54,24 +56,27 @@ class EmailChannel return; } - config()->set('mail.from.address', data_get($notifiable, 'smtp_from_address', 'test@example.com')); - config()->set('mail.from.name', data_get($notifiable, 'smtp_from_name', 'Test')); - if (data_get($notifiable, 'resend_enabled')) { + + config()->set('mail.from.address', $emailSettings->smtp_from_address ?? 'test@example.com'); + config()->set('mail.from.name', $emailSettings->smtp_from_name ?? 'Test'); + + if ($emailSettings->resend_enabled) { config()->set('mail.default', 'resend'); - config()->set('resend.api_key', data_get($notifiable, 'resend_api_key')); + config()->set('resend.api_key', $emailSettings->resend_api_key); } - if (data_get($notifiable, 'smtp_enabled')) { + + if ($emailSettings->smtp_enabled) { config()->set('mail.default', 'smtp'); config()->set('mail.mailers.smtp', [ 'transport' => 'smtp', - 'host' => data_get($notifiable, 'smtp_host'), - 'port' => data_get($notifiable, 'smtp_port'), - 'encryption' => data_get($notifiable, 'smtp_encryption') === 'none' ? null : data_get($notifiable, 'smtp_encryption'), - 'username' => data_get($notifiable, 'smtp_username'), - 'password' => data_get($notifiable, 'smtp_password'), - 'timeout' => data_get($notifiable, 'smtp_timeout'), + 'host' => $emailSettings->smtp_host, + 'port' => $emailSettings->smtp_port, + 'encryption' => $emailSettings->smtp_encryption === 'none' ? null : $emailSettings->smtp_encryption, + 'username' => $emailSettings->smtp_username, + 'password' => $emailSettings->smtp_password, + 'timeout' => $emailSettings->smtp_timeout, 'local_domain' => null, - 'auto_tls' => data_get($notifiable, 'smtp_encryption') === 'none' ? '0' : '', + 'auto_tls' => $emailSettings->smtp_encryption === 'none' ? '0' : '', ]); } }