ruby-on-rails - Rails 邮件拦截器仅用于特定邮件程序

标签 ruby-on-rails actionmailer interceptor

我有一个拦截器:DevelopmentMailInterceptor和初始化程序 setup_mail.rb启动拦截器。

但我想将它应用于特定的邮件程序(拦截 NotificationMailer 而不是其他邮件。

所以我设置在setup_mail.rb :

`NotificationMailer.register_interceptor(DevelopmentMailInterceptor) 

但随后所有邮件都被拦截了,就好像我写过一样
ActionMailer::Base.register_interceptor(DevelopmentMailInterceptor)

我怎样才能过滤这个?

最佳答案

我通过深入探索 message 找到了解决方案delivering_email 的参数邮件拦截器的方法。

class DevelopmentMailInterceptor
  def self.delivering_email(message)

    filteredMailers = %w[
      NotificationMailer
    ]

    if filteredMailers.include?(message.delivery_handler)
      message.subject = "[filter] To:#{message.to} - #{message.subject}"
      message.to = 'logs@mail.com'
    end

    return message
  end
end

@Intrepidd 的回答仍然正确,因为拦截器应用于整个 Mail类,但我找到了解决我想要实现的目标的方法。

关于ruby-on-rails - Rails 邮件拦截器仅用于特定邮件程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19408376/

相关文章:

ruby-on-rails - 每次更新数据库中的列时如何重新加载图表以显示更新的数据

ruby-on-rails - Rails 上的 Paypal 自适应支付给出错误的成功

ruby-on-rails - 多个数据库连接 : schema_migrations is looked up in the wrong database

ruby-on-rails - Actionmailer "Timeout::Error"有问题吗?

ruby-on-rails - 从 Controller 调用模块函数 (NoMethodError)

ruby-on-rails - 从使用 heroku 发送的邮件中删除 'via sendgrid.me'

ruby-on-rails - 如何在 ActionMailer 中使用 Devise 助手?

ParametersInterceptor - 捕获意外异常错误设置表达式 'x' 值为 '

angular - 如何设置{观察: 'response' } option globally in Angular 4. 3+?

ajax - 拦截器和 transformResponse 之间的确切区别是什么?