Files
nairobi/app/mailers/application_mailer.rb
Javi Martín d579bcce2d Allow rendering different email views per tenant
We were assigning variants in a controller, in the context of a request.
However, when sending emails, there is no request and no controller is
involved, so we also need to set the variant in the ApplicationMailer
class.
2022-11-29 14:01:22 +01:00

27 lines
690 B
Ruby

class ApplicationMailer < ActionMailer::Base
helper :application, :layouts, :mailer, :settings
default from: proc { "#{Setting["mailer_from_name"]} <#{Setting["mailer_from_address"]}>" }
layout "mailer"
before_action :set_asset_host
before_action :set_variant
after_action :set_smtp_settings
def default_url_options
Tenant.current_url_options
end
def set_asset_host
self.asset_host ||= root_url.delete_suffix("/")
end
def set_variant
lookup_context.variants = [Tenant.current_schema.to_sym]
end
def set_smtp_settings
unless Tenant.default?
mail.delivery_method.settings.merge!(Tenant.current_secrets.smtp_settings.to_h)
end
end
end