renz45 / mandrill_mailer

A small gem for sending Mandrill template emails
260 stars 84 forks source link

Interceptor params ignored when mailer is executed from the console #101

Closed andyzinsser closed 8 years ago

andyzinsser commented 9 years ago

I have an interceptor in place to keep the emails getting sent to real users' emails. This works great on our dev and staging environments. However, when generating an email locally from the rails console, the interceptor does not intercept and the email ends up actually getting delivered to the email from the DB and not from the interceptor.

The work around is to pass a proc as the interceptor instead of setting the interceptor_params.

Here is our mailer config file:

MandrillMailer.configure do |config|
  config.api_key = ENV['MANDRILL_APIKEY']
  unless Rails.env.production?
    # This was our existing setup that did not intercept when executing from the console
    # config.interceptor_params = {to: [{ email: ENV['INTERCEPTING_RECIPIENT'] }] }

    # This works on dev, staging, and from the console
    config.interceptor = Proc.new {|obj| obj[:to] = [{email: ENV['INTERCEPTING_RECIPIENT']}] }
  end
end
renz45 commented 8 years ago

Hi Andy, I apologize for the confusion. Interceptors were changed in 1.0.0 to always be procs. Your solution is the correct one. :)