Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3 send emails in development to a single address

In my Rails 2 apps I always used sanitize email to send all emails in development to my personal account to avoid accidentally sending out emails or to use just for testing.

This doesn't seem to have a Rails 3 version and wondered if there was anything for Rails 3 that does this.

like image 942
DEfusion Avatar asked Sep 10 '11 21:09

DEfusion


1 Answers

Take a look at How to intercept ActionMailer's messages on rails 3?. You'll only have to add message.to = my@email and the mail will be sent to your email address instead of the original destination.


This is what I ended up doing from the post linked to above:

if Rails.env.development?
    class Hook
        def self.delivering_email(message)
            message.to  = "\"#{message.to.first}\" <[email protected]>"
            message.cc  = nil if !message.cc.nil?
            message.bcc = nil if !message.bcc.nil?
        end
    end

    ActionMailer::Base.register_interceptor(Hook)
end
like image 91
eugen Avatar answered Sep 28 '22 06:09

eugen