如何在Rails 3上拦截ActionMailer的消息? [英] How to intercept ActionMailer's messages on rails 3?

查看:85
本文介绍了如何在Rails 3上拦截ActionMailer的消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Rails(3.0.10)应用程序中拦截消息以修改正文。虽然我能够找到一些有关如何执行此操作的信息,但似乎有所更改,现在使用旧方法不再有效。

I'm trying to intercept messages in my rails (3.0.10) app to modify the body. While I was able to find some info about how to do that, it seems something has changed and now using the old methods no longer work.

我使用的代码看起来像像这样:

I use a code that looks like this:

class Hook
  def self.delivering_email(message)
    message.subject = 'Hook changed the subject'
  end
end

ActionMailer::Base.register_interceptor(Hook)

发送电子邮件后,主题保持不变!

After sending an email, the subject doesn't get changed!

我还发现了一条鸣叫,指示使用 deliver 方法时未调用拦截器邮件上,但是 premailer-rails3 gem使用与我使用的方法相同的方法,并且在此处起作用(插件特别提到它可以与 deliver 方法一起使用)!

I also found a tweet that indicates that interceptors are not called when using the deliver method on messages, but the premailer-rails3 gem uses the same approach I used and it works there (The plugin specifically mentions it works with the deliver method)!

我在这里没什么主意,那该怎么办?

I'm out of ideas here, so what is causing my problem?

推荐答案

听起来好像是操作顺序问题。

It sounds like it might be an order of operations problem.

您是否考虑过将您引用的整个代码块放入诸如 config / initializers / mail_hook.rb 的初始化程序中?

Have you considered putting the entire code block you referenced in an initializer like config/initializers/mail_hook.rb?

如果该premailer插件有效,我唯一能想到的就是在应用初始化过程中注册了拦截钩。

If that premailer plugin works, the only difference I can think of is when the interception hook is registered in the app initialization process.

这篇关于如何在Rails 3上拦截ActionMailer的消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆