Skip to content

Commit e557e6b

Browse files
author
Peter Giacomo Lombardo
committed
Fix SMTP TLS failures from openssl_verify_mode Symbol conversion
Pass openssl_verify_mode as a String so the mail gem can map it to OpenSSL constants, wire PWP__MAIL__SMTP_STARTTLS to enable_starttls, and only report TestMailer success after delivery. Fixes #4005
1 parent f305ac9 commit e557e6b

4 files changed

Lines changed: 20 additions & 11 deletions

File tree

app/mailers/test_mailer.rb

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
class TestMailer < ApplicationMailer
2+
after_deliver :announce_test_email_success, only: :send_test_email
3+
24
def send_test_email(email)
35
puts ""
46
puts "--> Configured FROM: address: '#{Settings.mail.mailer_sender}'"
@@ -64,17 +66,21 @@ def send_test_email(email)
6466

6567
puts ""
6668
puts "--> Attempting to send a test email to #{email}..."
67-
mail(to: email,
68-
subject: "Test Email from Password Pusher",
69-
body: "⭐ If you are reading this, sending email works! ⭐ ")
70-
71-
puts "--> ✅ It seems that the Email was accepted by the SMTP server! Check destination inbox for the test email."
7269
puts ""
73-
7470
puts "--> If you see an error, please paste this output into a GitHub issue for help."
7571
puts " --> Make sure that no sensitive data is included."
7672
puts " --> https://github.com/pglombardo/PasswordPusher/issues/new/choose"
73+
puts ""
7774

75+
mail(to: email,
76+
subject: "Test Email from Password Pusher",
77+
body: "⭐ If you are reading this, sending email works! ⭐ ")
78+
end
79+
80+
private
81+
82+
def announce_test_email_success
83+
puts "--> ✅ It seems that the Email was accepted by the SMTP server! Check destination inbox for the test email."
7884
puts ""
7985
end
8086
end

config/defaults/settings.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ mail:
337337

338338
# When using TLS, you can set how OpenSSL checks the certificate. This is
339339
# useful if you need to validate a self-signed and/or a wildcard certificate.
340-
# This can be one of the OpenSSL verify constants, :none or :peer
340+
# Must be a string name of an OpenSSL verify constant: 'none' or 'peer'
341341
# Environment Variable Override: PWP__MAIL__SMTP_OPENSSL_VERIFY_MODE='none'
342342
# smtp_openssl_verify_mode: 'peer'
343343

config/environments/production.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,16 +163,19 @@
163163
config.action_mailer.smtp_settings[:password] = Settings.mail.smtp_password
164164
end
165165

166+
# Pass a String ("none" / "peer"). The mail gem maps strings to OpenSSL::SSL::VERIFY_*
167+
# constants; a Symbol like :none raises TypeError during TLS handshake.
166168
if !Settings.mail.smtp_openssl_verify_mode.nil?
167-
config.action_mailer.smtp_settings[:openssl_verify_mode] = Settings.mail.smtp_openssl_verify_mode.to_sym
169+
config.action_mailer.smtp_settings[:openssl_verify_mode] = Settings.mail.smtp_openssl_verify_mode.to_s
168170
end
169171

170172
if !Settings.mail.smtp_enable_starttls_auto.nil?
171173
config.action_mailer.smtp_settings[:enable_starttls_auto] = Settings.mail.smtp_enable_starttls_auto
172174
end
173175

174-
if !Settings.mail.smtp_enable_starttls.nil?
175-
config.action_mailer.smtp_settings[:enable_starttls] = Settings.mail.smtp_enable_starttls
176+
# settings.yml / PWP__MAIL__SMTP_STARTTLS maps to smtp_starttls
177+
if !Settings.mail.smtp_starttls.nil?
178+
config.action_mailer.smtp_settings[:enable_starttls] = Settings.mail.smtp_starttls
176179
end
177180
end
178181

config/settings.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ mail:
337337

338338
# When using TLS, you can set how OpenSSL checks the certificate. This is
339339
# useful if you need to validate a self-signed and/or a wildcard certificate.
340-
# This can be one of the OpenSSL verify constants, :none or :peer
340+
# Must be a string name of an OpenSSL verify constant: 'none' or 'peer'
341341
# Environment Variable Override: PWP__MAIL__SMTP_OPENSSL_VERIFY_MODE='none'
342342
# smtp_openssl_verify_mode: 'peer'
343343

0 commit comments

Comments
 (0)