Class: DaemonKit::ErrorHandlers::Mail
- Defined in:
- lib/daemon_kit/error_handlers/mail.rb
Overview
Send an email notification of the exception via SMTP.
Class Attribute Summary collapse
-
.authentication ⇒ Object
Returns the value of attribute authentication.
-
.domain ⇒ Object
Returns the value of attribute domain.
-
.host ⇒ Object
Returns the value of attribute host.
-
.password ⇒ Object
Returns the value of attribute password.
-
.port ⇒ Object
Returns the value of attribute port.
-
.prefix ⇒ Object
Returns the value of attribute prefix.
-
.recipients ⇒ Object
Returns the value of attribute recipients.
-
.sender ⇒ Object
Returns the value of attribute sender.
-
.tls ⇒ Object
Returns the value of attribute tls.
-
.username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
Methods inherited from Base
Class Attribute Details
.authentication ⇒ Object
Returns the value of attribute authentication.
40 41 42 |
# File 'lib/daemon_kit/error_handlers/mail.rb', line 40 def authentication @authentication end |
.domain ⇒ Object
Returns the value of attribute domain.
40 41 42 |
# File 'lib/daemon_kit/error_handlers/mail.rb', line 40 def domain @domain end |
.host ⇒ Object
Returns the value of attribute host.
40 41 42 |
# File 'lib/daemon_kit/error_handlers/mail.rb', line 40 def host @host end |
.password ⇒ Object
Returns the value of attribute password.
40 41 42 |
# File 'lib/daemon_kit/error_handlers/mail.rb', line 40 def password @password end |
.port ⇒ Object
Returns the value of attribute port.
40 41 42 |
# File 'lib/daemon_kit/error_handlers/mail.rb', line 40 def port @port end |
.prefix ⇒ Object
Returns the value of attribute prefix.
40 41 42 |
# File 'lib/daemon_kit/error_handlers/mail.rb', line 40 def prefix @prefix end |
.recipients ⇒ Object
Returns the value of attribute recipients.
40 41 42 |
# File 'lib/daemon_kit/error_handlers/mail.rb', line 40 def recipients @recipients end |
.sender ⇒ Object
Returns the value of attribute sender.
40 41 42 |
# File 'lib/daemon_kit/error_handlers/mail.rb', line 40 def sender @sender end |
.tls ⇒ Object
Returns the value of attribute tls.
40 41 42 |
# File 'lib/daemon_kit/error_handlers/mail.rb', line 40 def tls @tls end |
.username ⇒ Object
Returns the value of attribute username.
40 41 42 |
# File 'lib/daemon_kit/error_handlers/mail.rb', line 40 def username @username end |
Instance Method Details
#handle_exception(exception) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# 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.}" mail.set_content_type 'text', 'plain' mail.mime_version = '1.0' mail.date = Time.now mail.body = <<EOF DaemonKit caught an exception inside #{DaemonKit.configuration.daemon_name}. Message: #{exception.} Backtrace: #{exception.backtrace.join("\n ")} Environment: #{ENV.inspect} EOF 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.}" if DaemonKit.logger end end |