【问题标题】:Rails 3 send emails in development to a single addressRails 3 将开发中的电子邮件发送到单个地址
【发布时间】:2011-11-14 13:11:05
【问题描述】:

在我的 Rails 2 应用程序中,我总是使用 sanitize email 将开发中的所有电子邮件发送到我的个人帐户,以避免意外发送电子邮件或仅用于测试。

这似乎没有 Rails 3 版本,想知道 Rails 3 是否有任何东西可以做到这一点。

【问题讨论】:

    标签: ruby-on-rails-3 email actionmailer


    【解决方案1】:

    Ryan Bates(Railscasts) 刚刚发布了一个用于处理开发电子邮件的 gem。

    Letter_opener

    没用过,但应该值得一看。

    【讨论】:

      【解决方案2】:

      看看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
      

      【讨论】:

      • 太棒了!这对开发非常有用。
      • 您可能想使用Mail.register_interceptor(Hook) 而不是ActionMailer::Base.register_interceptor(Hook)
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-24
      • 1970-01-01
      • 1970-01-01
      • 2016-02-28
      • 1970-01-01
      • 2017-04-02
      相关资源
      最近更新 更多