From fd1a1d860f5669356513230068dddd23ecfe45b1 Mon Sep 17 00:00:00 2001 From: John Lemp Date: Thu, 19 Dec 2024 22:33:21 -0500 Subject: [PATCH] Add smtp email provider options and related settings. (#585) --- Gemfile.lock | 1 + config/initializers/email_feature.rb | 15 ++++++++++++++- config/options.yml | 6 ++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 1132121ce..42848495a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -492,6 +492,7 @@ PLATFORMS arm64-darwin-23 arm64-darwin-24 x86_64-darwin-22 + x86_64-darwin-23 x86_64-linux DEPENDENCIES diff --git a/config/initializers/email_feature.rb b/config/initializers/email_feature.rb index 1ef1faa05..b59725fc5 100644 --- a/config/initializers/email_feature.rb +++ b/config/initializers/email_feature.rb @@ -1,6 +1,7 @@ module Email class Providers POSTMARK = "postmark".freeze + SMTP = "smtp".freeze class << self def all @@ -27,11 +28,23 @@ class PasswordReset abort "ERROR: The value of EMAIL_PROVIDER must be one of: #{Email::Providers.all.join(", ")}" end - if Setting.email_provider == Email::Providers::POSTMARK + case Setting.email_provider + when Email::Providers::POSTMARK Setting.require_keys!(:postmark_server_api_token) config.action_mailer.delivery_method = :postmark config.action_mailer.postmark_settings = { api_token: Setting.postmark_server_api_token } + when Email::Providers::SMTP + Setting.require_keys!(:smtp_address, :smtp_user_name, :smtp_password) + config.action_mailer.delivery_method = :smtp + config.action_mailer.smtp_settings = { + address: Setting.smtp_address, + port: Setting.smtp_port.to_i, + user_name: Setting.smtp_user_name, + password: Setting.smtp_password, + authentication: Setting.smtp_authentication, + enable_starttls_auto: Setting.smtp_enable_starttls_auto.to_b + } end end end diff --git a/config/options.yml b/config/options.yml index 4cd6da6a2..784c4ee50 100644 --- a/config/options.yml +++ b/config/options.yml @@ -71,3 +71,9 @@ shared: email_from: <%= ENV["EMAIL_FROM"] || default_to(:email_from, except_env_test: "support@example.com") %> email_host: <%= ENV["EMAIL_HOST"] || default_to(:email_host, except_env_test: "example.com") %> postmark_server_api_token: <%= ENV["POSTMARK_SERVER_API_TOKEN"] || default_to(:postmark_server_api_token, except_env_test: "test-token") %> + smtp_address: <%= ENV["SMTP_ADDRESS"] || default_to(:smtp_address) %> + smtp_port: <%= ENV["SMTP_PORT"] || default_to(:smtp_port) || 587 %> + smtp_user_name: <%= ENV["SMTP_USER_NAME"] || default_to(:smtp_user_name) %> + smtp_password: <%= ENV["SMTP_PASSWORD"] || default_to(:smtp_password) %> + smtp_authentication: <%= ENV["SMTP_AUTHENTICATION"] || default_to(:smtp_authentication) || "plain" %> + smtp_enable_starttls_auto: <%= ENV["SMTP_ENABLE_STARTTLS_AUTO"] || default_to(:smtp_enable_starttls_auto) || true %>