Class: Yolo::Notify::Email

Inherits:
Object
  • Object
show all
Defined in:
lib/yolo/notify/email.rb

Overview

Sends emails via SMTP

Author:

  • Alex Fish

Direct Known Subclasses

Ios::OTAEmail

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEmail

Initilizes an instance of the class with default settings Loads defaults from Yolo::Config::Settings



29
30
31
32
33
34
35
36
37
38
# File 'lib/yolo/notify/email.rb', line 29

def initialize
  self.server = Yolo::Config::Settings.instance.mail_host
  self.from = Yolo::Config::Settings.instance.mail_from
  self.port = Yolo::Config::Settings.instance.mail_port
  self. = Yolo::Config::Settings.instance.
  self.password = Yolo::Config::Settings.instance.mail_password

  @error_formatter = Yolo::Formatters::ErrorFormatter.new
  @progress_formatter = Yolo::Formatters::ProgressFormatter.new
end

Instance Attribute Details

#accountObject

The email account to use when sending mail



21
22
23
# File 'lib/yolo/notify/email.rb', line 21

def 
  @account
end

#fromObject

The email address used in the from feild



15
16
17
# File 'lib/yolo/notify/email.rb', line 15

def from
  @from
end

#passwordObject

The account password to use when sending mail



23
24
25
# File 'lib/yolo/notify/email.rb', line 23

def password
  @password
end

#portObject

The port to use when sending mail



19
20
21
# File 'lib/yolo/notify/email.rb', line 19

def port
  @port
end

#serverObject

An SMTP server



17
18
19
# File 'lib/yolo/notify/email.rb', line 17

def server
  @server
end

#toObject

An array of email addresses used in the to field



13
14
15
# File 'lib/yolo/notify/email.rb', line 13

def to
  @to
end

Instance Method Details

#body(opts) ⇒ Object

The body of them notification email, this method should be overwritten in subclasses to provide custom content

Parameters:

  • opts (Hash)

    A populated options hash, allows the use of options when generating email content



82
83
84
# File 'lib/yolo/notify/email.rb', line 82

def body(opts)
  ""
end

#send(opts = {}) ⇒ Object

Sends a nofification email using SMTP

Parameters:

  • opts (Hash) (defaults to: {})

    An options hash, options are: server, from, subject, title, body, password, account, port, to



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/yolo/notify/email.rb', line 44

def send(opts={})

  opts[:server]      ||= self.server
  opts[:from]        ||= self.from
  opts[:subject]     ||= "New Build!"
  opts[:title]       ||= "New Build!"
  opts[:body]        ||= body(opts)
  opts[:password]    ||= self.password
  opts[:account]     ||= self.
  opts[:port]        ||= self.port
  opts[:to]          ||= self.to

  msg = opts[:body]

  if opts[:account] and opts[:password] and opts[:port] and opts[:to]
    @progress_formatter.sending_email
    smtp = Net::SMTP.new opts[:server], opts[:port]
    smtp.enable_starttls
    smtp.start(opts[:server], opts[:account], opts[:password], :login) do
      smtp.send_message(msg, opts[:from], opts[:to])
      @progress_formatter.email_sent(opts[:to])
    end
  elsif opts[:server] and opts[:to]
    @progress_formatter.sending_email
    Net::SMTP.start(opts[:server]) do |smtp|
      smtp.send_message(msg, opts[:from], opts[:to])
      @progress_formatter.email_sent(opts[:to])
    end
  else
    @error_formatter.missing_email_details
  end
end