开发者

Log emails sent by devise in rails

开发者 https://www.devze.com 2023-04-02 20:44 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消