improve SMTP configs form
This commit is contained in:
@@ -19,11 +19,7 @@ module ActionMailerConfigsInterceptor
|
||||
email_configs = EncryptedConfig.find_by(key: EncryptedConfig::EMAIL_SMTP_KEY)
|
||||
|
||||
if email_configs
|
||||
message.delivery_method(:smtp, user_name: email_configs.value['username'],
|
||||
password: email_configs.value['password'],
|
||||
address: email_configs.value['host'],
|
||||
port: email_configs.value['port'],
|
||||
tls: email_configs.value['port'].to_s == '465')
|
||||
message.delivery_method(:smtp, build_smtp_configs_hash(email_configs))
|
||||
|
||||
message.from = "#{email_configs.account.name} <#{email_configs.value['from_email']}>"
|
||||
else
|
||||
@@ -32,4 +28,20 @@ module ActionMailerConfigsInterceptor
|
||||
|
||||
message
|
||||
end
|
||||
|
||||
def build_smtp_configs_hash(email_configs)
|
||||
value = email_configs.value
|
||||
|
||||
{
|
||||
user_name: value['username'],
|
||||
password: value['password'],
|
||||
address: value['host'],
|
||||
port: value['port'],
|
||||
domain: value['domain'],
|
||||
authentication: value.fetch('authentication', 'plain'),
|
||||
enable_starttls_auto: true,
|
||||
ssl: value['security'] == 'ssl',
|
||||
tls: value['security'] == 'tls' || (value['security'].blank? && value['port'].to_s == '465')
|
||||
}.compact_blank
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user