FIX: in EmailSettingsValidator, unset smtp authentication when there's no user and password
net-smtp 0.5.0 bails when authentication is set without username/password followup-to:7b8d60dc
,897be759
This commit is contained in:
parent
dc996a1e5c
commit
a5ef7b1999
|
@ -65,8 +65,7 @@ class EmailSettingsValidator
|
||||||
# For Gmail, the port should be 587, enable_starttls_auto should be true,
|
# For Gmail, the port should be 587, enable_starttls_auto should be true,
|
||||||
# and enable_tls should be false.
|
# and enable_tls should be false.
|
||||||
#
|
#
|
||||||
# @param domain [String] - Used for HELO, will be the email sender's domain, so often
|
# @param domain [String] - Used for HELO, should be the FQDN of the server sending the mail
|
||||||
# will just be the host e.g. the domain for test@gmail.com is gmail.com.
|
|
||||||
# localhost can be used in development mode.
|
# localhost can be used in development mode.
|
||||||
# See https://datatracker.ietf.org/doc/html/rfc788#section-4
|
# See https://datatracker.ietf.org/doc/html/rfc788#section-4
|
||||||
# @param debug [Boolean] - When set to true, any errors will be logged at a warning
|
# @param debug [Boolean] - When set to true, any errors will be logged at a warning
|
||||||
|
@ -77,7 +76,7 @@ class EmailSettingsValidator
|
||||||
username:,
|
username:,
|
||||||
password:,
|
password:,
|
||||||
domain: nil,
|
domain: nil,
|
||||||
authentication: GlobalSetting.smtp_authentication,
|
authentication: nil,
|
||||||
enable_starttls_auto: GlobalSetting.smtp_enable_start_tls,
|
enable_starttls_auto: GlobalSetting.smtp_enable_start_tls,
|
||||||
enable_tls: GlobalSetting.smtp_force_tls,
|
enable_tls: GlobalSetting.smtp_force_tls,
|
||||||
openssl_verify_mode: GlobalSetting.smtp_openssl_verify_mode,
|
openssl_verify_mode: GlobalSetting.smtp_openssl_verify_mode,
|
||||||
|
@ -91,8 +90,13 @@ class EmailSettingsValidator
|
||||||
raise ArgumentError, "TLS and STARTTLS are mutually exclusive"
|
raise ArgumentError, "TLS and STARTTLS are mutually exclusive"
|
||||||
end
|
end
|
||||||
|
|
||||||
if !%i[plain login cram_md5].include?(authentication.to_sym)
|
if username || password
|
||||||
raise ArgumentError, "Invalid authentication method. Must be plain, login, or cram_md5."
|
authentication = (authentication || GlobalSetting.smtp_authentication)&.to_sym
|
||||||
|
if !%i[plain login cram_md5].include?(authentication)
|
||||||
|
raise ArgumentError, "Invalid authentication method. Must be plain, login, or cram_md5."
|
||||||
|
end
|
||||||
|
else
|
||||||
|
authentication = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
if domain.blank?
|
if domain.blank?
|
||||||
|
@ -127,7 +131,7 @@ class EmailSettingsValidator
|
||||||
smtp.open_timeout = 5
|
smtp.open_timeout = 5
|
||||||
smtp.read_timeout = 5
|
smtp.read_timeout = 5
|
||||||
|
|
||||||
smtp.start(domain, username, password, authentication.to_sym)
|
smtp.start(domain, username, password, authentication)
|
||||||
smtp.finish
|
smtp.finish
|
||||||
rescue => err
|
rescue => err
|
||||||
log_and_raise(err, debug)
|
log_and_raise(err, debug)
|
||||||
|
|
|
@ -84,7 +84,7 @@ task "emails:test", [:email] => [:environment] do |_, args|
|
||||||
domain: smtp[:domain] || "localhost",
|
domain: smtp[:domain] || "localhost",
|
||||||
username: smtp[:user_name],
|
username: smtp[:user_name],
|
||||||
password: smtp[:password],
|
password: smtp[:password],
|
||||||
authentication: smtp[:authentication] || "plain",
|
authentication: smtp[:authentication],
|
||||||
)
|
)
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
if e.to_s.match(/execution expired/)
|
if e.to_s.match(/execution expired/)
|
||||||
|
|
Loading…
Reference in New Issue