Augustin Riedinger
Augustin Riedinger

Reputation: 22198

Rails ActionMailer : filter emails to a specific list in development

Without editing any of my /app files, I'd like to edit either development.rb or an initializer where I set a whitelist of testers.

Then the emails are sent only to those people in the whitelist (not to spam other users mailbox).

I though of overriding deliver!, or the user.get_mail method but :

Upvotes: 1

Views: 1053

Answers (1)

Intrepidd
Intrepidd

Reputation: 20878

You might want to check out Action mailer interceptors

And do something like this :

class BetaEmailInterceptor
  def self.delivering_email(message)
    message.perform_deliveries = false unless WHITELIST.include?(message.to.first)
  end
end

And

ActionMailer::Base.register_interceptor(BetaEmailInterceptor)

This is a very naive implementation and will only work if the first recipient is whitelisted but you get the idea.

Upvotes: 3

Related Questions