docbrown/app/models/settings/smtp.rb
Ridhwana b21397a8c6
"Reply to" and "From" Email addresses for SMTP Configurations (#16499)
* feat: create a from_email_address and a reply_to_email_address

* feat: update other mailers with the new SMTP email settings

* test: update all spec files

* fix: use the SMTP::Settings value

* fix tests

* spec: fix the comma

* feat: tighten some logic

* fix: test

* fix tests

* fix tests

* final fix test commit

* fix test

* fix test

* oops

* feat: add a reply_to for Devise Mailer

* chore: update the description

* use a proc for reply_to

* feat: update text

* Update spec/mailers/digest_mailer_spec.rb

Co-authored-by: Julianna Tetreault <32834804+juliannatetreault@users.noreply.github.com>

* Update spec/mailers/verification_mailer_spec.rb

Co-authored-by: Julianna Tetreault <32834804+juliannatetreault@users.noreply.github.com>

* Update spec/mailers/shared_examples/renders_proper_email_headers.rb

Co-authored-by: Julianna Tetreault <32834804+juliannatetreault@users.noreply.github.com>

* refactor: move OPTIONS to a helper as its only being used in the view layer

Co-authored-by: Julianna Tetreault <32834804+juliannatetreault@users.noreply.github.com>
2022-02-16 16:14:54 +02:00

49 lines
1.8 KiB
Ruby

module Settings
class SMTP < Base
self.table_name = :settings_smtp
AUTHENTICATION_METHODS = %w[plain login cram_md5].freeze
setting :address, type: :string, default: ApplicationConfig["SMTP_ADDRESS"].presence
setting :authentication, type: :string, default: ApplicationConfig["SMTP_AUTHENTICATION"].presence,
validates: { inclusion: AUTHENTICATION_METHODS }
setting :domain, type: :string, default: ApplicationConfig["SMTP_DOMAIN"].presence
setting :password, type: :string, default: ApplicationConfig["SMTP_PASSWORD"].presence
setting :port, type: :integer, default: ApplicationConfig["SMTP_PORT"].presence || 25
setting :user_name, type: :string, default: ApplicationConfig["SMTP_USER_NAME"].presence
setting :from_email_address, type: :string, default: ApplicationConfig["DEFAULT_EMAIL"].presence,
validates: { email: true, allow_blank: true }
setting :reply_to_email_address, type: :string, default: ApplicationConfig["DEFAULT_EMAIL"].presence,
validates: { email: true, allow_blank: true }
class << self
def settings
if provided_minimum_settings?
custom_provider_settings
else
fallback_sendgrid_settings
end
end
def provided_minimum_settings?
address.present? && user_name.present? && password.present?
end
private
def custom_provider_settings
to_h
end
def fallback_sendgrid_settings
{
address: "smtp.sendgrid.net",
port: 587,
authentication: :plain,
user_name: "apikey",
password: ENV["SENDGRID_API_KEY"],
domain: ::Settings::General.app_domain
}
end
end
end
end