class ExceptionMailer::Mailer
Attributes
account[R]
from[R]
host[R]
password[R]
port[R]
server[R]
subject[R]
to[R]
Public Class Methods
new(opts)
click to toggle source
# File lib/exception_mailer/mailer.rb, line 7 def initialize(opts) @host = opts[:host] || ExceptionMailer.host @server = opts[:server] || ExceptionMailer.server @port = opts[:port] || ExceptionMailer.port @account = opts[:account] || ExceptionMailer.account @password = opts[:password] || ExceptionMailer.password @auth_method = opts[:auth_method] || ExceptionMailer.auth_method @to = opts[:to] || ExceptionMailer.to @from = opts[:from] || ExceptionMailer.from @subject = opts[:subject] || ExceptionMailer.subject @to = [ @to ] unless @to.kind_of? Array end
Public Instance Methods
send_notification(exception)
click to toggle source
# File lib/exception_mailer/mailer.rb, line 21 def send_notification(exception) Net::SMTP.start(*start_args) do |smtp| smtp.send_message(build_msg(exception), from, *to) end end
Private Instance Methods
body(exception)
click to toggle source
# File lib/exception_mailer/mailer.rb, line 48 def body(exception) [ "#{exception.class}: #{exception.message}", "#{exception.backtrace.join("\n")}" ].join("\n") end
build_msg(exception)
click to toggle source
# File lib/exception_mailer/mailer.rb, line 36 def build_msg(exception) <<-END_OF_MESSAGE From: <#{from}> #{to.map { |t| "To: <#{t}>" }.join("\n") } Subject: #{subject} Date: #{now} Message-Id: <#{msg_id}> #{body(exception)} END_OF_MESSAGE end
msg_id()
click to toggle source
# File lib/exception_mailer/mailer.rb, line 55 def msg_id rand(1_000_000_000) end
now()
click to toggle source
# File lib/exception_mailer/mailer.rb, line 59 def now Time.now end
start_args()
click to toggle source
# File lib/exception_mailer/mailer.rb, line 29 def start_args [ :server, :port, :host, :account, :password, :auth_method ].inject([]) do |args, arg| return args if send(arg).nil? args << send(arg) end end