How to put BCC in Devise 3.0.0 for Rails 3.2.9?

560 views Asked by At

I'm have already tried to rewrite the headers_for, but it's still not working. Here goes my code: app/mailers/devise_notifier.rb:

class DeviseNotifier < Devise::Mailer    
  def headers_for(action, opts)
    super.merge!({bcc: '[email protected]'})
  end
end

app/config/initializers/devise.rb:

Devise.setup do |config|
  config.mailer = "DeviseNotifier"
  ...
end
1

There are 1 answers

5
gregates On

headers_for helper already merges opts with the default headers. I'd try overwriting send_devise_notification on your user model (or whatever the devise resource is).

def send_devise_notification(notification, opts={})
  opts.merge!({bcc: '[email protected]'})
  devise_mailer.send(notification, opts).deliver
end

or for devise 3.1 or later:

def send_devise_notification(notification, *args)
  opts = args.extract_options!
  args.push(opts.merge({bcc: '[email protected]'}))
  devise_mailer.send(notification, self, *args).deliver
end