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
-
#content_type ⇒ Object
Returns the value of attribute content_type.
-
#data ⇒ Object
Returns the value of attribute data.
-
#host ⇒ Object
Returns the value of attribute host.
-
#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
18 19 20 21 22 23 24 25 |
# File 'lib/request_log_analyzer/mailer.rb', line 18 def initialize(to, host = 'localhost', = {}) require 'net/smtp' @to = to @host = host = @data = [] @content_type = nil end |
Instance Attribute Details
#content_type ⇒ Object
Returns the value of attribute content_type.
6 7 8 |
# File 'lib/request_log_analyzer/mailer.rb', line 6 def content_type @content_type end |
#data ⇒ Object
Returns the value of attribute data.
6 7 8 |
# File 'lib/request_log_analyzer/mailer.rb', line 6 def data @data end |
#host ⇒ Object
Returns the value of attribute host.
6 7 8 |
# File 'lib/request_log_analyzer/mailer.rb', line 6 def host @host end |
#to ⇒ Object
Returns the value of attribute to.
6 7 8 |
# File 'lib/request_log_analyzer/mailer.rb', line 6 def to @to end |
Instance Method Details
#<<(string) ⇒ Object
53 54 55 |
# File 'lib/request_log_analyzer/mailer.rb', line 53 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 |
# 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.to_s}" content_type= "Content-Type: #{@content_type}" if @content_type msg = "From: \#{from_alias} <\#{from}>\nTo: \#{to_alias} <\#{@to}>\nSubject: \#{subject}\n\#{content_type}\n\n\#{@data.to_s}\n" unless [:debug] Net::SMTP.start(@host) do |smtp| smtp. msg, from, to end end return [msg, from, to] end |
#puts(string) ⇒ Object
57 58 59 |
# File 'lib/request_log_analyzer/mailer.rb', line 57 def puts string data << string end |