Do I need to create a separate mailer to copy myself when a user registers through Devise?
I have Devise implemented in a Rails 3 application, with the :registera开发者_JAVA技巧ble and :confirmable options. A users receives a confirmation email, no problem.
However, I want to send an additional email to another address when a person registers or confirms. I will probably use the Observer pattern for this.
But can I use the same mailer, whatever/wherever that is, that Devise uses, or must I create another?
Devise will invoke a 'headers_for' method if you have one on your model (e.g. User).
I didn't use an Observer, but I added this method to my User class to add a bcc address and override the subject line:
def headers_for(action)
if action == :confirmation_instructions
{ bcc: "sent-mail@company.com", subject: "Welcome to the App!" }
else
{}
end
end
Devise then merges these in to it's defaults.
I worked this out by reading Devise's source code.
See: https://github.com/plataformatec/devise/blob/master/app/mailers/devise/mailer.rb#L42
精彩评论