module ExceptionAlarm class Mailer < ActionMailer::Base self.mailer_name = 'mailer' self.append_view_path "#{File.dirname(__FILE__)}/views" thread_local_accessor :prefix, default: '[ERROR]' thread_local_accessor :sender, default: 'exception@example.com' thread_local_accessor :recipients def alarm(env, exception) @env = env @exception = exception @kontroller = env['action_controller.instance'] @request = ActionDispatch::Request.new(env) mail( from: self.class.sender, to: self.class.recipients, subject: "#{self.class.prefix} (#{@exception.class}) #{@exception.message.inspect}" ) end end end