2016-11-15 15:56:29 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-03-19 18:20:07 +00:00
|
|
|
class ApplicationMailer < ActionMailer::Base
|
|
|
|
layout 'mailer'
|
2018-01-16 02:29:11 +00:00
|
|
|
|
2018-01-28 23:22:20 +00:00
|
|
|
helper :application
|
2017-04-17 22:16:32 +00:00
|
|
|
helper :instance
|
2017-06-26 22:04:00 +00:00
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def locale_for_account(account)
|
|
|
|
I18n.with_locale(account.user_locale || I18n.default_locale) do
|
|
|
|
yield
|
|
|
|
end
|
|
|
|
end
|
2023-02-07 03:19:21 +00:00
|
|
|
|
|
|
|
class DynamicSettingsInterceptor
|
|
|
|
class << self
|
|
|
|
def delivering_email(message)
|
|
|
|
set_second_delivery_options(message) if use_second?(message)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def use_second?(message)
|
|
|
|
return unless Rails.configuration.x.second_smtp_settings[:address]
|
|
|
|
|
|
|
|
Rails.configuration.x.domains_to_use_second_smtp&.any? { |domain| recipient_domains(message).include?(domain) }
|
|
|
|
end
|
|
|
|
|
|
|
|
def recipient_domains(message)
|
|
|
|
message.recipients_addresses.map(&:domain).compact
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_second_delivery_options(message)
|
|
|
|
message.delivery_method.settings.merge!(Rails.configuration.x.second_smtp_settings)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
register_interceptor DynamicSettingsInterceptor
|
2016-03-19 18:20:07 +00:00
|
|
|
end
|