module RequestLogAnalyzer
class Mailer
attr_accessor :data, :to, :host
# Initialize a mailer
# to to address
# host the mailer host
# options Specific style options
# Options
# :debug Do not actually mail
def initialize(to, host = 'localhost', options = {})
require 'net/smtp'
@to = to
@host = host
@options = options
@data = []
end
def mail
from = @options[:from] || 'contact@railsdoctors.com'
from_alias = @options[:from_alias] || 'Request-log-analyzer reporter'
to_alias = @options[:to_alias] || to
subject = @options[:subjeect] || "Request log analyzer report - generated on #{Time.now.to_s}"
msg = <
To: #{to_alias} <#{@to}>
Subject: #{subject}
#{@data.to_s}
END_OF_MESSAGE
unless @options[:debug]
Net::SMTP.start(@host) do |smtp|
smtp.send_message msg, from, to
end
end
return [msg, from, to]
end
def << string
data << string
end
def puts string
data << string
end
end
end