DEfusion
DEfusion

Reputation: 5613

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.

Upvotes: 5

Views: 1041

Answers (2)

eugen
eugen

Reputation: 9226

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

Upvotes: 6

David Barlow
David Barlow

Reputation: 4974

Ryan Bates(Railscasts) has just released a gem for handling dev emails.

Letter_opener

Haven't used it but probably worth a look.

Upvotes: 4

Related Questions