lib/request_log_analyzer/mailer.rb in request-log-analyzer-1.4.2 vs lib/request_log_analyzer/mailer.rb in request-log-analyzer-1.5.0

- old
+ new

@@ -1,11 +1,11 @@ module RequestLogAnalyzer # Mail report to a specified emailaddress class Mailer - attr_accessor :data, :to, :host + attr_accessor :data, :to, :host, :port # Initialize a mailer # <tt>to</tt> to email address to mail to # <tt>host</tt> the mailer host (defaults to localhost) # <tt>options</tt> Specific style options @@ -17,12 +17,15 @@ # * <tt>:subject</tt> The message subject def initialize(to, host = 'localhost', options = {}) require 'net/smtp' @to = to @host = host + + @port = 25 @options = options - @data = [] + @host, @port = host.split(':') if @host.include?(':') + @data = [] end # 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. def mail @@ -36,14 +39,14 @@ From: #{from_alias} <#{from}> To: #{to_alias} <#{@to}> Subject: #{subject} #{content_type} -#{@data.to_s} +#{@data.join("\n")} END_OF_MESSAGE unless @options[:debug] - Net::SMTP.start(@host) do |smtp| + Net::SMTP.start(@host, @port) do |smtp| smtp.send_message msg, from, to end end return [msg, from, to] \ No newline at end of file