Parent

DaemonKit::ErrorHandlers::Mail

Send an email notification of the exception via SMTP.

Attributes

authentication[RW]
domain[RW]
host[RW]
password[RW]
port[RW]
prefix[RW]
recipients[RW]
sender[RW]
tls[RW]
username[RW]

Public Instance Methods

handle_exception( exception ) click to toggle source
# File lib/daemon_kit/error_handlers/mail.rb, line 53
def handle_exception( exception )

  mail = TMail::Mail.new
  mail.to = self.class.recipients
  mail.from = self.class.sender
  mail.subject = "#{self.class.prefix} #{exception.message}"
  mail.set_content_type 'text', 'plain'
  mail.mime_version = '1.0'
  mail.date = Time.now

  mail.body = DaemonKit caught an exception inside #{DaemonKit.configuration.daemon_name}.Message: #{exception.message}Backtrace:#{exception.backtrace.join("\n  ")}Environment: #{ENV.inspect}
  begin
    smtp = Net::SMTP.new( self.class.host, self.class.port )
    smtp.enable_starttls_auto if self.class.tls && smtp.respond_to?(:enable_starttls_auto)
    smtp.start( self.class.domain, self.class.username, self.class.password,
                self.class.authentication ) do |smtp|
      smtp.sendmail( mail.to_s, mail.from, mail.to )
    end
  rescue => e
    DaemonKit.logger.error "Failed to send exception mail: #{e.message}" if DaemonKit.logger
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.