Skip to content

Commit

Permalink
Add smtp email provider options and related settings. (#585)
Browse files Browse the repository at this point in the history
  • Loading branch information
duckworth authored Dec 20, 2024
1 parent 2dc5a8a commit fd1a1d8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ PLATFORMS
arm64-darwin-23
arm64-darwin-24
x86_64-darwin-22
x86_64-darwin-23
x86_64-linux

DEPENDENCIES
Expand Down
15 changes: 14 additions & 1 deletion config/initializers/email_feature.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Email
class Providers
POSTMARK = "postmark".freeze
SMTP = "smtp".freeze

class << self
def all
Expand 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
6 changes: 6 additions & 0 deletions config/options.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>

0 comments on commit fd1a1d8

Please sign in to comment.