DEV: Use EmailSettingsValidator in more places (#15404)
Clears out a long-standing TODO I added back in
3d2cace94f
, this way we are only
validating these settings using one central class.
This commit is contained in:
parent
4a0f73a337
commit
8a26ea23f6
|
@ -80,30 +80,22 @@ task 'emails:test', [:email] => [:environment] do |_, args|
|
||||||
|
|
||||||
puts "Testing sending to #{email} using #{smtp[:address]}:#{smtp[:port]}, username:#{smtp[:user_name]} with #{smtp[:authentication]} auth."
|
puts "Testing sending to #{email} using #{smtp[:address]}:#{smtp[:port]}, username:#{smtp[:user_name]} with #{smtp[:authentication]} auth."
|
||||||
|
|
||||||
# TODO (martin, post-2.7 release) Change to use EmailSettingsValidator
|
# We are not formatting the messages using EmailSettingsExceptionHandler here
|
||||||
# EmailSettingsValidator.validate_smtp(
|
# because we are doing custom messages in the rake task with more details.
|
||||||
# host: smtp[:address],
|
EmailSettingsValidator.validate_smtp(
|
||||||
# port: smtp[:port],
|
host: smtp[:address],
|
||||||
# domain: smtp[:domain] || 'localhost',
|
port: smtp[:port],
|
||||||
# username: smtp[:user_name],
|
domain: smtp[:domain] || 'localhost',
|
||||||
# password: smtp[:password],
|
username: smtp[:user_name],
|
||||||
# authentication: smtp[:authentication] || 'plain'
|
password: smtp[:password],
|
||||||
# )
|
authentication: smtp[:authentication] || 'plain'
|
||||||
|
)
|
||||||
# We would like to do this, but Net::SMTP errors out using starttls
|
|
||||||
#Net::SMTP.start(smtp[:address], smtp[:port]) do |s|
|
|
||||||
# s.starttls if !!smtp[:enable_starttls_auto] && s.capable_starttls?
|
|
||||||
# s.auth_login(smtp[:user_name], smtp[:password])
|
|
||||||
#end
|
|
||||||
|
|
||||||
Net::SMTP.start(smtp[:address], smtp[:port], smtp[:domain] || 'localhost', smtp[:user_name], smtp[:password], smtp[:authentication])
|
|
||||||
|
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
|
|
||||||
if e.to_s.match(/execution expired/)
|
if e.to_s.match(/execution expired/)
|
||||||
message = <<~STR
|
message = <<~STR
|
||||||
======================================== ERROR ========================================
|
======================================== ERROR ========================================
|
||||||
Connection to port #{ENV["DISCOURSE_SMTP_PORT"]} failed.
|
Connection to port #{smtp[:port]} failed.
|
||||||
====================================== SOLUTION =======================================
|
====================================== SOLUTION =======================================
|
||||||
The most likely problem is that your server has outgoing SMTP traffic blocked.
|
The most likely problem is that your server has outgoing SMTP traffic blocked.
|
||||||
If you are using a service like Mailgun or Sendgrid, try using port 2525.
|
If you are using a service like Mailgun or Sendgrid, try using port 2525.
|
||||||
|
|
|
@ -33,20 +33,16 @@ class POP3PollingEnabledSettingValidator
|
||||||
private
|
private
|
||||||
|
|
||||||
def authentication_works?
|
def authentication_works?
|
||||||
# TODO (martin, post-2.7 release) Change to use EmailSettingsValidator
|
|
||||||
# EmailSettingsValidator.validate_pop3(
|
|
||||||
# host: SiteSetting.pop3_polling_host,
|
|
||||||
# port: SiteSetting.pop3_polling_port,
|
|
||||||
# ssl: SiteSetting.pop3_polling_ssl,
|
|
||||||
# username: SiteSetting.pop3_polling_username,
|
|
||||||
# password: SiteSetting.pop3_polling_password,
|
|
||||||
# openssl_verify: SiteSetting.pop3_polling_openssl_verify
|
|
||||||
# )
|
|
||||||
@authentication_works ||= begin
|
@authentication_works ||= begin
|
||||||
pop3 = Net::POP3.new(SiteSetting.pop3_polling_host, SiteSetting.pop3_polling_port)
|
EmailSettingsValidator.validate_pop3(
|
||||||
pop3.enable_ssl(OpenSSL::SSL::VERIFY_NONE) if SiteSetting.pop3_polling_ssl
|
host: SiteSetting.pop3_polling_host,
|
||||||
pop3.auth_only(SiteSetting.pop3_polling_username, SiteSetting.pop3_polling_password)
|
port: SiteSetting.pop3_polling_port,
|
||||||
rescue Net::POPAuthenticationError
|
ssl: SiteSetting.pop3_polling_ssl,
|
||||||
|
username: SiteSetting.pop3_polling_username,
|
||||||
|
password: SiteSetting.pop3_polling_password,
|
||||||
|
openssl_verify: SiteSetting.pop3_polling_openssl_verify
|
||||||
|
)
|
||||||
|
rescue *EmailSettingsExceptionHandler::EXPECTED_EXCEPTIONS => err
|
||||||
false
|
false
|
||||||
else
|
else
|
||||||
true
|
true
|
||||||
|
|
Loading…
Reference in New Issue