Skip to content

A platform for community discussion. Free, open, simple.

FIX: SMTP: explicitly disable STARTTLS when TLS is enabled

Michael Brown6f8cc76a3ddd
diff --git a/app/models/global_setting.rb b/app/models/global_setting.rb
index beda62dd1a3..03d5ef81889 100644
--- a/app/models/global_setting.rb
+++ b/app/models/global_setting.rb
@@ -272,7 +272,7 @@ class GlobalSetting
domain: GlobalSetting.smtp_domain,
user_name: GlobalSetting.smtp_user_name,
password: GlobalSetting.smtp_password,
- enable_starttls_auto: GlobalSetting.smtp_enable_start_tls,
+ enable_starttls_auto: !GlobalSetting.smtp_force_tls && GlobalSetting.smtp_enable_start_tls,
open_timeout: GlobalSetting.smtp_open_timeout,
read_timeout: GlobalSetting.smtp_read_timeout,
}
diff --git a/app/services/email_settings_validator.rb b/app/services/email_settings_validator.rb
index c23c45d82e5..38ec33c5daa 100644
--- a/app/services/email_settings_validator.rb
+++ b/app/services/email_settings_validator.rb
@@ -74,7 +74,7 @@ class EmailSettingsValidator
password:,
domain: nil,
authentication: nil,
- enable_starttls_auto: GlobalSetting.smtp_enable_start_tls,
+ enable_starttls_auto: !GlobalSetting.smtp_force_tls && GlobalSetting.smtp_enable_start_tls,
enable_tls: GlobalSetting.smtp_force_tls,
openssl_verify_mode: GlobalSetting.smtp_openssl_verify_mode,
debug: Rails.env.development?
diff --git a/spec/integration/smtp_spec.rb b/spec/integration/smtp_spec.rb
index 38ef1cfb603..87b5ae3e145 100644
--- a/spec/integration/smtp_spec.rb
+++ b/spec/integration/smtp_spec.rb
@@ -12,6 +12,22 @@ RSpec.describe "SMTP Settings Integration" do
ActionMailer::Base.delivery_method = @original_action_mailer_delivery_method
end
+ it "should disable starttls_auto when tls is enabled" do
+ global_setting :smtp_address, "localhost"
+ global_setting :smtp_port, 465
+ global_setting :smtp_force_tls, true
+
+ expect(GlobalSetting.smtp_settings[:enable_starttls_auto]).to be_falsey
+ end
+
+ it "should leave starttls_auto enabled when tls is not enabled" do
+ global_setting :smtp_address, "localhost"
+ global_setting :smtp_port, 587
+ global_setting :smtp_force_tls, false
+
+ expect(GlobalSetting.smtp_settings[:enable_starttls_auto]).to be_truthy
+ end
+
it "should attempt to send out an email without raising any SMTP argument errors" do
global_setting :smtp_address, "1.2.3.4"
global_setting :smtp_port, 12_345