Last active
August 25, 2020 09:01
-
-
Save ritikesh/d768b13aba9ea85db60c60d371b7457c to your computer and use it in GitHub Desktop.
blog gists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MailboxInterceptor | |
def self.delivering_email(mail) | |
set_smtp_settings(mail) | |
fix_encodings | |
ensure | |
unset_email_config | |
end | |
private | |
def self.set_smtp_settings(mail) | |
smtp_settings = tenant_mail_config&.smtp_settings : default_smtp_settings | |
ActionMailer.smtp_settings = smtp_settings | |
mail.delivery_method(:smtp, smtp_settings) | |
end | |
def unset_email_config | |
Thread.current[:tenant_mail_config] = nil | |
end | |
def tenant_mail_config=(mail_config) | |
Thread.current[:tenant_mail_config] = mail_config | |
end | |
def tenant_mail_config | |
Thread.current[:tenant_mail_config] | |
end | |
end | |
ActionMailer::Base.register_interceptor(MailboxInterceptor) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment