Class: RequestLogAnalyzer::Mailer
- Inherits:
-
Object
- Object
- RequestLogAnalyzer::Mailer
- Defined in:
- lib/request_log_analyzer/mailer.rb
Overview
Mail report to a specified emailaddress
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#host ⇒ Object
Returns the value of attribute host.
-
#port ⇒ Object
Returns the value of attribute port.
-
#to ⇒ Object
Returns the value of attribute to.
Instance Method Summary collapse
- #<<(string) ⇒ Object
-
#initialize(to, host = 'localhost', options = {}) ⇒ Mailer
constructor
Initialize a mailer
toto email address to mail tohostthe mailer host (defaults to localhost)optionsSpecific style options. -
#mail ⇒ Object
Send all data in @data to the email address used during initialization.
- #puts(string) ⇒ Object
Constructor Details
#initialize(to, host = 'localhost', options = {}) ⇒ Mailer
Initialize a mailer to to email address to mail to host the mailer host (defaults to localhost) options Specific style options
Options
-
:debugDo not actually mail -
:from_aliasThe from alias -
:to_aliasThe to alias -
:subjectThe message subject
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/request_log_analyzer/mailer.rb', line 16 def initialize(to, host = 'localhost', = {}) require 'net/smtp' @to = to @host = host @port = 25 = @host, @port = host.split(':') if @host.include?(':') @data = [] end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
4 5 6 |
# File 'lib/request_log_analyzer/mailer.rb', line 4 def data @data end |
#host ⇒ Object
Returns the value of attribute host.
4 5 6 |
# File 'lib/request_log_analyzer/mailer.rb', line 4 def host @host end |
#port ⇒ Object
Returns the value of attribute port.
4 5 6 |
# File 'lib/request_log_analyzer/mailer.rb', line 4 def port @port end |
#to ⇒ Object
Returns the value of attribute to.
4 5 6 |
# File 'lib/request_log_analyzer/mailer.rb', line 4 def to @to end |
Instance Method Details
#<<(string) ⇒ Object
54 55 56 |
# File 'lib/request_log_analyzer/mailer.rb', line 54 def <<(string) data << string end |
#mail ⇒ Object
Send all data in @data to the email address used during initialization. Returns array containg [message_data, from_email_address, to_email_address] of sent email.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/request_log_analyzer/mailer.rb', line 29 def mail from = [:from] || '[email protected]' from_alias = [:from_alias] || 'Request-log-analyzer reporter' to_alias = [:to_alias] || to subject = [:subject] || "Request log analyzer report - generated on #{Time.now}" content_type = '' content_type = 'Content-Type: text/html; charset="ISO-8859-1";' if @data.map { |l| l.include?('html') }.include?(true) msg = "From: \#{from_alias} <\#{from}>\nTo: \#{to_alias} <\#{@to}>\nSubject: \#{subject}\n\#{content_type}\n\n\#{@data.join(\"\\n\")}\n" unless [:debug] Net::SMTP.start(@host, @port) do |smtp| smtp. msg, from, to end end [msg, from, to] end |
#puts(string) ⇒ Object
58 59 60 |
# File 'lib/request_log_analyzer/mailer.rb', line 58 def puts(string) data << string end |