Skip to content

Instantly share code, notes, and snippets.

@leschenko
Created June 5, 2014 10:49
Show Gist options
  • Save leschenko/72c417235bf3d22d8e38 to your computer and use it in GitHub Desktop.
Save leschenko/72c417235bf3d22d8e38 to your computer and use it in GitHub Desktop.
save undeliveded emails
class ApplicationMailer < ActionMailer::Base
def self.deliver_mail(mail, &block)
begin
super(mail, &block)
rescue => e
begin
dir = Rails.root.join('data/exception_emails')
FileUtils.mkdir_p(dir)
path = File.join(dir, "#{Time.current.to_s(:path)}__#{mail.object_id}.eml")
File.write(path, mail.to_s)
Utils.mail_logger.exception(e, data: {mail: mail.inspect, path: path})
ExceptionNotifier.notify_exception(e, data: {mail: mail.inspect, path: path})
rescue
false
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment