1

We send out many emails through Rails (and then through Amazon SES). I'd like to now log all of those emails in our database so we know exactly which emails were sent where and all the details. I'd also love to know which class/method sent those emails or some way to tag them.

This must be an extremely common need, so I'm curious if there's a mechanism with Rails to automatically handle this?

at.
  • 50,922
  • 104
  • 292
  • 461
  • Check this post: http://stackoverflow.com/questions/3525145/email-open-notification-ruby-on-rails It can help you man – lucianosousa Mar 20 '15 at 00:06
  • @lucianosousa - that is about checking if someone opened an email, not the same thing as I'm asking. I want to log into my database whenever my Rails app sends out an email. – at. Mar 20 '15 at 02:00

1 Answers1

2

mail-logger gem captures the info about the emails sent, and log them to a file.

With a little bit of work it could be customized to write to a database instead.

The gem is overriding delivered_email method to log the details:

class Mail::Logger::Callback
  def self.delivered_email(email)
    Mail::Logger.logger.info email.inspect
  end
end
Prakash Murthy
  • 12,923
  • 3
  • 46
  • 74