From 619a5575237b132dad30fc9776382f01f05e5f58 Mon Sep 17 00:00:00 2001 From: kaioken Date: Wed, 29 May 2024 16:00:54 -0400 Subject: [PATCH 1/4] refact: email provider --- .../Apps/Support/SmtpRuntimeConfiguration.php | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/Kanvas/Apps/Support/SmtpRuntimeConfiguration.php b/src/Kanvas/Apps/Support/SmtpRuntimeConfiguration.php index 2b73e9893..d1d061f1e 100644 --- a/src/Kanvas/Apps/Support/SmtpRuntimeConfiguration.php +++ b/src/Kanvas/Apps/Support/SmtpRuntimeConfiguration.php @@ -7,6 +7,7 @@ use Baka\Contracts\AppInterface; use Baka\Contracts\CompanyInterface; use Baka\Contracts\HashTableInterface; +use Illuminate\Support\Facades\Config; class SmtpRuntimeConfiguration { @@ -24,15 +25,30 @@ public function __construct( /** * Load SMTP settings from the given source. */ - protected function loadSmtpSettingsFromSource(string $provider, HashTableInterface $source): void + protected function loadSmtpSettingsFromSource(string $provider, HashTableInterface $source): string { - config([ - "mail.mailers.{$provider}.host" => $source->get('smtp_host'), - "mail.mailers.{$provider}.port" => $source->get('smtp_port'), - "mail.mailers.{$provider}.username" => $source->get('smtp_username'), - "mail.mailers.{$provider}.password" => $source->get('smtp_password'), - "mail.mailers.{$provider}.encryption" => $source->get('smtp_encryption') ?? 'tls' - ]); + $fromAddress = $this->getFromEmail(); + $config = [ + 'driver' => $source->get('smtp_driver') ?? 'smtp', + 'host' => $source->get('smtp_host'), + 'port' => $source->get('smtp_port'), + 'from' => [ + 'address' => $fromAddress['address'], + 'name' => $fromAddress['name'], + ], + 'encryption' => $source->get('smtp_encryption') ?? 'tls', + 'username' => $source->get('smtp_username'), + 'password' => $source->get('smtp_password'), + ]; + + Config::set('mail.mailers.' . $provider, $config); + + return $provider; + } + + protected function resetMailConfig(): void + { + Config::set('mail', config('mail.default')); } /** @@ -57,6 +73,8 @@ protected function loadCompanySettings(): void */ public function loadSmtpSettings(): string { + $this->resetMailConfig(); + if ($this->company !== null && $this->company->get('smtp_host')) { $this->loadCompanySettings(); From ff1d0b8b370d6fdcc2adbdef1c9dade38aabac96 Mon Sep 17 00:00:00 2001 From: kaioken Date: Wed, 29 May 2024 16:09:27 -0400 Subject: [PATCH 2/4] refact: email provider --- .../Apps/Support/SmtpRuntimeConfiguration.php | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/Kanvas/Apps/Support/SmtpRuntimeConfiguration.php b/src/Kanvas/Apps/Support/SmtpRuntimeConfiguration.php index d1d061f1e..a650bcd13 100644 --- a/src/Kanvas/Apps/Support/SmtpRuntimeConfiguration.php +++ b/src/Kanvas/Apps/Support/SmtpRuntimeConfiguration.php @@ -29,7 +29,7 @@ protected function loadSmtpSettingsFromSource(string $provider, HashTableInterfa { $fromAddress = $this->getFromEmail(); $config = [ - 'driver' => $source->get('smtp_driver') ?? 'smtp', + 'driver' => 'smtp', 'host' => $source->get('smtp_host'), 'port' => $source->get('smtp_port'), 'from' => [ @@ -39,6 +39,7 @@ protected function loadSmtpSettingsFromSource(string $provider, HashTableInterfa 'encryption' => $source->get('smtp_encryption') ?? 'tls', 'username' => $source->get('smtp_username'), 'password' => $source->get('smtp_password'), + 'timeout' => null, ]; Config::set('mail.mailers.' . $provider, $config); @@ -54,17 +55,17 @@ protected function resetMailConfig(): void /** * Load SMTP settings from the app. */ - protected function loadAppSettings(): void + protected function loadAppSettings(): string { - $this->loadSmtpSettingsFromSource($this->appSmtp, $this->app); + return $this->loadSmtpSettingsFromSource($this->appSmtp, $this->app); } /** * Load SMTP settings from the company config. */ - protected function loadCompanySettings(): void + protected function loadCompanySettings(): string { - $this->loadSmtpSettingsFromSource($this->companySmtp, $this->company); + return $this->loadSmtpSettingsFromSource($this->companySmtp, $this->company); } /** @@ -76,13 +77,9 @@ public function loadSmtpSettings(): string $this->resetMailConfig(); if ($this->company !== null && $this->company->get('smtp_host')) { - $this->loadCompanySettings(); - - return $this->companySmtp; + return $this->loadCompanySettings(); } elseif ($this->app->get('smtp_host')) { - $this->loadAppSettings(); - - return $this->appSmtp; + return $this->loadAppSettings(); } return $this->defaultSmtp; From 264aaa703d3e2c56e63f02cb62bb5bc2f05726f1 Mon Sep 17 00:00:00 2001 From: kaioken Date: Wed, 29 May 2024 17:17:52 -0400 Subject: [PATCH 3/4] refact: email provider --- .../Apps/Support/SmtpRuntimeConfiguration.php | 17 +++-------------- src/Kanvas/Notifications/Notification.php | 2 +- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/src/Kanvas/Apps/Support/SmtpRuntimeConfiguration.php b/src/Kanvas/Apps/Support/SmtpRuntimeConfiguration.php index a650bcd13..784050541 100644 --- a/src/Kanvas/Apps/Support/SmtpRuntimeConfiguration.php +++ b/src/Kanvas/Apps/Support/SmtpRuntimeConfiguration.php @@ -27,15 +27,10 @@ public function __construct( */ protected function loadSmtpSettingsFromSource(string $provider, HashTableInterface $source): string { - $fromAddress = $this->getFromEmail(); $config = [ - 'driver' => 'smtp', + 'transport' => 'smtp', 'host' => $source->get('smtp_host'), 'port' => $source->get('smtp_port'), - 'from' => [ - 'address' => $fromAddress['address'], - 'name' => $fromAddress['name'], - ], 'encryption' => $source->get('smtp_encryption') ?? 'tls', 'username' => $source->get('smtp_username'), 'password' => $source->get('smtp_password'), @@ -47,10 +42,6 @@ protected function loadSmtpSettingsFromSource(string $provider, HashTableInterfa return $provider; } - protected function resetMailConfig(): void - { - Config::set('mail', config('mail.default')); - } /** * Load SMTP settings from the app. @@ -74,8 +65,6 @@ protected function loadCompanySettings(): string */ public function loadSmtpSettings(): string { - $this->resetMailConfig(); - if ($this->company !== null && $this->company->get('smtp_host')) { return $this->loadCompanySettings(); } elseif ($this->app->get('smtp_host')) { @@ -92,8 +81,8 @@ public function getFromEmail(): array { if ($this->company !== null && $this->company->get('from_email_address')) { return [ - 'name' => $this->company->get('from_email_name'), - 'address' => $this->company->get('from_email_address'), + 'name' => $this->company->get('from_email_name') ?? config('mail.from.name'), + 'address' => $this->company->get('from_email_address') ?? config('mail.from.address'), ]; } diff --git a/src/Kanvas/Notifications/Notification.php b/src/Kanvas/Notifications/Notification.php index 87055d29d..b69735103 100644 --- a/src/Kanvas/Notifications/Notification.php +++ b/src/Kanvas/Notifications/Notification.php @@ -149,7 +149,7 @@ public function toMail($notifiable): ?MailMessage $fromEmail = $fromMail['address']; $fromName = $fromMail['name']; - + $mailMessage = (new MailMessage()) ->mailer($mailer) ->from($fromEmail, $fromName) From 85a3ae91c7de1664b86edb292ee3a557be443249 Mon Sep 17 00:00:00 2001 From: kaioken Date: Wed, 29 May 2024 17:19:23 -0400 Subject: [PATCH 4/4] refact: email provider --- src/Kanvas/Notifications/Notification.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Kanvas/Notifications/Notification.php b/src/Kanvas/Notifications/Notification.php index b69735103..e7e3753b3 100644 --- a/src/Kanvas/Notifications/Notification.php +++ b/src/Kanvas/Notifications/Notification.php @@ -40,6 +40,7 @@ class Notification extends LaravelNotification implements EmailInterfaces, Shoul protected ?UserInterface $fromUser = null; protected ?UserInterface $toUser = null; protected ?CompanyInterface $company = null; + public ?array $pathAttachment = null; public array $channels = [ 'mail', @@ -149,7 +150,7 @@ public function toMail($notifiable): ?MailMessage $fromEmail = $fromMail['address']; $fromName = $fromMail['name']; - + $mailMessage = (new MailMessage()) ->mailer($mailer) ->from($fromEmail, $fromName)