在我的 Rails 2 应用程序中,我总是使用 sanitize email将开发中的所有电子邮件发送到我的个人帐户,以避免意外发送电子邮件或仅用于测试。
这似乎没有 Rails 3 版本,想知道 Rails 3 是否有任何东西可以做到这一点。
最佳答案
看看How to intercept ActionMailer's messages on rails 3? .您只需添加 message.to = my@email
并且邮件将发送到您的电子邮件地址而不是原始目的地。
这就是我从上面链接的帖子中最终做的事情:
if Rails.env.development?
class Hook
def self.delivering_email(message)
message.to = "\"#{message.to.first}\" <my@email.com>"
message.cc = nil if !message.cc.nil?
message.bcc = nil if !message.bcc.nil?
end
end
ActionMailer::Base.register_interceptor(Hook)
end
关于ruby-on-rails-3 - Rails 3 将开发中的电子邮件发送到单个地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7374874/