docbrown/app/mailers/application_mailer.rb
Michael Kohl b7ff9aadd1
Clean up SiteConfig (#13738)
* Remove obsolete SiteConfig values

* Remove DUS

* fixup! Remove obsolete SiteConfig values

* fixup! Remove obsolete SiteConfig values

* Add DUS for removing SiteConfig values

* Fix specs

* Fix specs

* Clean up more DUS

* Update DUS

* Fix remaining spec

* Remove leftover spec

* Fix more specs

* Fix spec

* Remove deprecated spec

* Rearrange specs

* Temporarily disable specs
2021-05-18 09:38:31 +07:00

38 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
before_action :use_custom_host
default(
from: -> { email_from },
template_path: ->(mailer) { "mailers/#{mailer.class.name.underscore}" },
)
def email_from(topic = "")
community_name = if topic.present?
"#{Settings::Community.community_name} #{topic}"
else
Settings::Community.community_name
end
"#{community_name} <#{SiteConfig.email_addresses[:default]}>"
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] = SiteConfig.app_domain
end
end