Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add smtp email provider options and related settings. #585

Merged
merged 4 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 %>
Loading