Class: Ruport::Report::Mailer

Inherits:
Object
  • Object
show all
Defined in:
lib/ruport/report/mailer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mailer_label = :default) ⇒ Mailer

Returns a new instance of Mailer.



12
13
14
15
16
# File 'lib/ruport/report/mailer.rb', line 12

def initialize( mailer_label=:default )
  select_mailer(mailer_label)
  @body = ""
  @recipients = []
end

Instance Attribute Details

#bodyObject

The body of the message to be sent



22
23
24
# File 'lib/ruport/report/mailer.rb', line 22

def body
  @body
end

#recipientsObject

A list of email addresses to send the message to.



19
20
21
# File 'lib/ruport/report/mailer.rb', line 19

def recipients
  @recipients
end

Instance Method Details

#select_mailer(label) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/ruport/report/mailer.rb', line 35

def select_mailer(label)
  mailer      = Ruport::Config.mailers[label]
  @host       = mailer.host
  @user       = mailer.user
  @password   = mailer.password
  @address    = mailer.address
  @port       = mailer.port       || 25
  @auth       = mailer.auth_type  || :plain
end

#send_report(report_name = "No Subject") ⇒ Object

This takes report_name as argument and sends the contents of @body to



26
27
28
29
30
31
32
33
# File 'lib/ruport/report/mailer.rb', line 26

def send_report(report_name="No Subject")
  return if @body.empty?
  Net::SMTP.start(@host,@port,@host,@user,@password,@auth) do |smtp|
    smtp.send_message( "Subject: #{report_name}\n\n#{@body}",
                       @address, 
                       @recipients )
  end
end