Class: Torque::Mailer

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

Overview

Handles sending the finished release notes document to a list of emails after Torque generates it

Instance Method Summary collapse

Constructor Details

#initialize(email, password) ⇒ Mailer

Creates a Mailer that will send emails from the email address/password combo given

Parameters:

  • email

    An email address

  • password

    A password that matches the email address given



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/torque/mailer.rb', line 14

def initialize(email, password)
  @email = email
  @password = password

  options = { :address              => "smtp.gmail.com",
              :port                 => 587,
              :domain               => 'gmail.com',
              :user_name            => @email,
              :password             => @password,
              :authentication       => 'plain',
              :enable_starttls_auto => true }

  Mail.defaults do
    delivery_method :smtp, options
  end
end

Instance Method Details

#send_notes(notes_string, subject_line, address_list) ⇒ Object

Sends notes_string as an email with subject_line from an arbitrary email address to everyone on address_list

Parameters:

  • notes_string

    The release notes file in string form

  • subject_line

    The subject line to use in the email

  • address_list

    A comma-separated list of email addresses to which to send the notes



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/torque/mailer.rb', line 36

def send_notes(notes_string, subject_line, address_list)

  mail = Mail::Message.new
  
  mail.charset = "UTF-8"
  mail.to        address_list
  mail.from      @email
  mail.subject   subject_line
  mail.body      notes_string
  
  begin
    mail.deliver
  rescue Net::SMTPAuthenticationError
    # TODO Remove this output. Should fail silently and be replaced by an independent call to :verify 
    puts "Username and password not accepted by Gmail. Check your username and password or try using a Gmail " \
      "account"
  end

end