0

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: 'my@mail.com'})
  end
end

app/config/initializers/devise.rb:

Devise.setup do |config|
  config.mailer = "DeviseNotifier"
  ...
end
  • Could you open up the question also on the text field, not only on title. I think also more details about the situation are needed. – mico Sep 13 '13 at 19:21
  • Had an answer but I think it may have been more complicated than necessary. The first question is: did you tell devise to use your custom mailer in `config/initializers/devise.rb` with `config.mailer = "DeviseNotifier"`? – gregates Sep 13 '13 at 21:42
  • Yes, @gregates : `Devise.setup do |config| config.mailer_sender = "my@email.com.br" config.mailer = "DeviseNotifier" ... end` – Filipe Magalhães Sep 16 '13 at 14:00

1 Answers1

1

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: 'my@mail.com'})
  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: 'my@mail.com'}))
  devise_mailer.send(notification, self, *args).deliver
end
gregates
  • 6,607
  • 1
  • 31
  • 31
  • I've tried this and got this error: _"ArgumentError: wrong number of arguments (3 for 2)"_ I found [here](https://github.com/plataformatec/devise/blob/6b3b0c5e8c57253d3d178def678ccc26e66cd630/lib/devise/models/authenticatable.rb) that the function `send_devise_notification` can be rewritable. But the arguments are: `(notification, *args)`. So I couldn't modify the `opts` – Filipe Magalhães Sep 16 '13 at 14:39
  • That's true on devise 3.1, but I thought you were using 3.0? On 3.0, it's `send_devise_notification(notification, opts={})` – gregates Sep 16 '13 at 15:10
  • Oops, I see what happened -- I originally had a version that would work in 3.1, and when I tried to change it for your version, I left out one crucial change. – gregates Sep 16 '13 at 15:11
  • I've tried everything that you said (even updated to devise 3.1.0), but still not working. Just to be sure that I'm on the right way, I put **CC** instead of **BCC** and it worked. – Filipe Magalhães Sep 16 '13 at 20:59
  • do you have still any other try? – Filipe Magalhães Sep 25 '13 at 18:55