diff --git a/.gitignore b/.gitignore index 95ad8c38..dd1db6a5 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,4 @@ yarn-debug.log* /coverage /attachments /docuseal +/ee diff --git a/app/controllers/email_settings_controller.rb b/app/controllers/email_settings_controller.rb index d648f636..3412b98a 100644 --- a/app/controllers/email_settings_controller.rb +++ b/app/controllers/email_settings_controller.rb @@ -7,10 +7,16 @@ class EmailSettingsController < ApplicationController def create if @encrypted_config.update(storage_configs) + SettingsMailer.smtp_successful_setup(@encrypted_config.value['from_email']).deliver_now! + redirect_to settings_email_index_path, notice: 'Changes have been saved' else render :index, status: :unprocessable_entity end + rescue Net::SMTPError, OpenSSL::SSL::SSLError, Net::ReadTimeout => e + flash[:alert] = e.message + + render :index, status: :unprocessable_entity end private diff --git a/app/javascript/application.scss b/app/javascript/application.scss index 0c21e19d..4cb86b4f 100644 --- a/app/javascript/application.scss +++ b/app/javascript/application.scss @@ -70,3 +70,7 @@ button[disabled] .enabled { .base-radio { @apply radio bg-white radio-sm no-animation; } + +.base-select { + @apply select base-input w-full font-normal; +} diff --git a/app/mailers/settings_mailer.rb b/app/mailers/settings_mailer.rb new file mode 100644 index 00000000..2aefcf3a --- /dev/null +++ b/app/mailers/settings_mailer.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class SettingsMailer < ApplicationMailer + def smtp_successful_setup(email) + mail(to: email, subject: 'SMTP has been configured') + end +end diff --git a/app/views/accounts/show.html.erb b/app/views/accounts/show.html.erb index 0f5ec8ab..bb97c819 100644 --- a/app/views/accounts/show.html.erb +++ b/app/views/accounts/show.html.erb @@ -11,13 +11,13 @@
SMTP has been successfully configured!
diff --git a/lib/action_mailer_configs_interceptor.rb b/lib/action_mailer_configs_interceptor.rb index 5ff9f2f7..16646791 100644 --- a/lib/action_mailer_configs_interceptor.rb +++ b/lib/action_mailer_configs_interceptor.rb @@ -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 diff --git a/spec/mailers/previews/settings_mailer_preview.rb b/spec/mailers/previews/settings_mailer_preview.rb new file mode 100644 index 00000000..09068c01 --- /dev/null +++ b/spec/mailers/previews/settings_mailer_preview.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class SettingsMailerPreview < ActionMailer::Preview + def smtp_successful_setup + SettingsMailer.smtp_successful_setup('example@gmail.com') + end +end