From 1f499c148867295b1db3f329330c01d7e4d3fe8a Mon Sep 17 00:00:00 2001 From: Vishwanath Martur <64204611+vishwamartur@users.noreply.github.com> Date: Sat, 23 Nov 2024 13:04:54 +0530 Subject: [PATCH 1/4] Add no encryption option for SMTP settings Related to #4311 Add option to configure SMTP settings without encryption. * Update `app/Livewire/Notifications/Email.php` and `app/Livewire/SettingsEmail.php` to include "No Encryption" option in the `smtpEncryption` field and update validation rules. * Modify `app/Notifications/Channels/EmailChannel.php` to handle the "No Encryption" option in the `bootConfigs` method. * Add `set_transanctional_email_settings` function in `app/Livewire/Help.php` to support the "No Encryption" option. * Update `config/mail.php` to handle the "No Encryption" option in the mail configuration. --- app/Livewire/Help.php | 32 +++++++++++++++++++++ app/Livewire/Notifications/Email.php | 2 +- app/Livewire/SettingsEmail.php | 2 +- app/Notifications/Channels/EmailChannel.php | 2 +- config/mail.php | 2 +- 5 files changed, 36 insertions(+), 4 deletions(-) diff --git a/app/Livewire/Help.php b/app/Livewire/Help.php index f51527fbe..aa354e94e 100644 --- a/app/Livewire/Help.php +++ b/app/Livewire/Help.php @@ -56,3 +56,35 @@ class Help extends Component return view('livewire.help')->layout('layouts.app'); } } + +function set_transanctional_email_settings($settings = null) +{ + if (is_null($settings)) { + $settings = instanceSettings(); + } + + if ($settings->resend_enabled) { + config()->set('mail.default', 'resend'); + config()->set('resend.api_key', $settings->resend_api_key); + + return 'resend'; + } + + if ($settings->smtp_enabled) { + config()->set('mail.default', 'smtp'); + config()->set('mail.mailers.smtp', [ + 'transport' => 'smtp', + 'host' => $settings->smtp_host, + 'port' => $settings->smtp_port, + 'encryption' => $settings->smtp_encryption === 'none' ? null : $settings->smtp_encryption, + 'username' => $settings->smtp_username, + 'password' => $settings->smtp_password, + 'timeout' => $settings->smtp_timeout, + 'local_domain' => null, + ]); + + return 'smtp'; + } + + return false; +} diff --git a/app/Livewire/Notifications/Email.php b/app/Livewire/Notifications/Email.php index fcedf1305..682180aa8 100644 --- a/app/Livewire/Notifications/Email.php +++ b/app/Livewire/Notifications/Email.php @@ -37,7 +37,7 @@ class Email extends Component #[Validate(['nullable', 'numeric'])] public ?int $smtpPort = null; - #[Validate(['nullable', 'string'])] + #[Validate(['nullable', 'string', 'in:tls,ssl,none'])] public ?string $smtpEncryption = null; #[Validate(['nullable', 'string'])] diff --git a/app/Livewire/SettingsEmail.php b/app/Livewire/SettingsEmail.php index 61f720b3a..abf3a12f9 100644 --- a/app/Livewire/SettingsEmail.php +++ b/app/Livewire/SettingsEmail.php @@ -19,7 +19,7 @@ class SettingsEmail extends Component #[Validate(['nullable', 'numeric', 'min:1', 'max:65535'])] public ?int $smtpPort = null; - #[Validate(['nullable', 'string'])] + #[Validate(['nullable', 'string', 'in:tls,ssl,none'])] public ?string $smtpEncryption = null; #[Validate(['nullable', 'string'])] diff --git a/app/Notifications/Channels/EmailChannel.php b/app/Notifications/Channels/EmailChannel.php index af9af978d..e745990e4 100644 --- a/app/Notifications/Channels/EmailChannel.php +++ b/app/Notifications/Channels/EmailChannel.php @@ -66,7 +66,7 @@ class EmailChannel 'transport' => 'smtp', 'host' => data_get($notifiable, 'smtp_host'), 'port' => data_get($notifiable, 'smtp_port'), - 'encryption' => data_get($notifiable, 'smtp_encryption'), + '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'), diff --git a/config/mail.php b/config/mail.php index 26af507d9..b36bd363c 100644 --- a/config/mail.php +++ b/config/mail.php @@ -38,7 +38,7 @@ return [ 'transport' => 'smtp', 'host' => env('MAIL_HOST', 'smtp.mailgun.org'), 'port' => env('MAIL_PORT', 587), - 'encryption' => env('MAIL_ENCRYPTION', 'tls'), + 'encryption' => env('MAIL_ENCRYPTION', 'tls') === 'none' ? null : env('MAIL_ENCRYPTION', 'tls'), 'username' => env('MAIL_USERNAME'), 'password' => env('MAIL_PASSWORD'), 'timeout' => null, From a836d78f0bb7716134f2424d917636046b41e91a Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 25 Nov 2024 14:07:50 +0100 Subject: [PATCH 2/4] remove unnecessary function --- app/Livewire/Help.php | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/app/Livewire/Help.php b/app/Livewire/Help.php index aa354e94e..f51527fbe 100644 --- a/app/Livewire/Help.php +++ b/app/Livewire/Help.php @@ -56,35 +56,3 @@ class Help extends Component return view('livewire.help')->layout('layouts.app'); } } - -function set_transanctional_email_settings($settings = null) -{ - if (is_null($settings)) { - $settings = instanceSettings(); - } - - if ($settings->resend_enabled) { - config()->set('mail.default', 'resend'); - config()->set('resend.api_key', $settings->resend_api_key); - - return 'resend'; - } - - if ($settings->smtp_enabled) { - config()->set('mail.default', 'smtp'); - config()->set('mail.mailers.smtp', [ - 'transport' => 'smtp', - 'host' => $settings->smtp_host, - 'port' => $settings->smtp_port, - 'encryption' => $settings->smtp_encryption === 'none' ? null : $settings->smtp_encryption, - 'username' => $settings->smtp_username, - 'password' => $settings->smtp_password, - 'timeout' => $settings->smtp_timeout, - 'local_domain' => null, - ]); - - return 'smtp'; - } - - return false; -} From a500daac9855009d07454cf21b810b4953fdff36 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 5 Dec 2024 12:42:31 +0100 Subject: [PATCH 3/4] fixes --- config/mail.php | 2 +- resources/views/livewire/notifications/email.blade.php | 10 +++++++--- resources/views/livewire/settings-email.blade.php | 7 +++++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/config/mail.php b/config/mail.php index b36bd363c..26af507d9 100644 --- a/config/mail.php +++ b/config/mail.php @@ -38,7 +38,7 @@ return [ 'transport' => 'smtp', 'host' => env('MAIL_HOST', 'smtp.mailgun.org'), 'port' => env('MAIL_PORT', 587), - 'encryption' => env('MAIL_ENCRYPTION', 'tls') === 'none' ? null : env('MAIL_ENCRYPTION', 'tls'), + 'encryption' => env('MAIL_ENCRYPTION', 'tls'), 'username' => env('MAIL_USERNAME'), 'password' => env('MAIL_PASSWORD'), 'timeout' => null, diff --git a/resources/views/livewire/notifications/email.blade.php b/resources/views/livewire/notifications/email.blade.php index 182c73d6a..fba21d0b2 100644 --- a/resources/views/livewire/notifications/email.blade.php +++ b/resources/views/livewire/notifications/email.blade.php @@ -17,7 +17,8 @@ @if (isEmailEnabled($team) && auth()->user()->isAdminFromSession() && isTestEmailEnabled($team))
- + Send Email @@ -62,8 +63,11 @@
- + + + + +
diff --git a/resources/views/livewire/settings-email.blade.php b/resources/views/livewire/settings-email.blade.php index ff3e4bfb8..141922584 100644 --- a/resources/views/livewire/settings-email.blade.php +++ b/resources/views/livewire/settings-email.blade.php @@ -33,8 +33,11 @@
- + + + + +
From 80f649b96a880819e72b16a5e0b7bca46ec04436 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 5 Dec 2024 13:09:06 +0100 Subject: [PATCH 4/4] finally found the right option --- app/Notifications/Channels/EmailChannel.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Notifications/Channels/EmailChannel.php b/app/Notifications/Channels/EmailChannel.php index e745990e4..5394f6106 100644 --- a/app/Notifications/Channels/EmailChannel.php +++ b/app/Notifications/Channels/EmailChannel.php @@ -71,6 +71,7 @@ class EmailChannel 'password' => data_get($notifiable, 'smtp_password'), 'timeout' => data_get($notifiable, 'smtp_timeout'), 'local_domain' => null, + 'auto_tls' => data_get($notifiable, 'smtp_encryption') === 'none' ? '0' : '', ]); } }