docbrown/app/mailers/application_mailer.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

40 lines
1.4 KiB
Ruby

class ApplicationMailer < ActionMailer::Base
layout "mailer"
# the order of importing the helpers here is important
# we want the application helpers to override the Rails route helpers should there be a name conflict
# an example is the user_url
helper Rails.application.routes.url_helpers
helper ApplicationHelper
helper AuthenticationHelper
include Deliverable
before_action :use_custom_host
default(
from: -> { email_from },
template_path: ->(mailer) { "mailers/#{mailer.class.name.underscore}" },
reply_to: -> { ForemInstance.reply_to_email_address },
)
def email_from(topic = "")
community_name = if topic.present?
"#{Settings::Community.community_name} #{topic}"
else
Settings::Community.community_name
end
"#{community_name} <#{ForemInstance.from_email_address}>"
end
def generate_unsubscribe_token(id, email_type)
Rails.application.message_verifier(:unsubscribe).generate({
user_id: id,
email_type: email_type.to_sym,
expires_at: 31.days.from_now
})
end
def use_custom_host
ActionMailer::Base.default_url_options[:host] = Settings::General.app_domain
end
end