Log emails sent by devise in rails
I am using devise for user authentication in rails. How can I log the emails sent by devise. I开发者_开发百科 have a model for storing the emails. How can I hook in so that before devise sends emails for new registration, change password, forgot password etc, I can just store the emails in the db?
Create a file called config/initializers/devise_mail_logger.rb
and re-open the Devise::Mailer class
devise_mail_logger.rb:
Devise::Mailer.class_eval do
def devise_mail_with_logger(record, action)
email = devise_mail_without_logger(record, action)
#code to log this email to DB goes here
end
alias_method_chain :devise_mail, :logger
end
The email
object will have the message body, subject, recipient details. You can pass this object to the model you have to store emails.
精彩评论