Class: Yolo::Notify::Email
- Inherits:
-
Object
- Object
- Yolo::Notify::Email
- Defined in:
- lib/yolo/notify/email.rb
Overview
Sends emails via SMTP
Direct Known Subclasses
Instance Attribute Summary collapse
-
#account ⇒ Object
The email account to use when sending mail.
-
#from ⇒ Object
The email address used in the from feild.
-
#password ⇒ Object
The account password to use when sending mail.
-
#port ⇒ Object
The port to use when sending mail.
-
#server ⇒ Object
An SMTP server.
-
#to ⇒ Object
An array of email addresses used in the to field.
Instance Method Summary collapse
-
#body(opts) ⇒ Object
The body of them notification email, this method should be overwritten in subclasses to provide custom content.
-
#initialize ⇒ Email
constructor
Initilizes an instance of the class with default settings Loads defaults from Yolo::Config::Settings.
-
#send(opts = {}) ⇒ Object
Sends a nofification email using SMTP.
Constructor Details
#initialize ⇒ Email
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.account = Yolo::Config::Settings.instance.mail_account self.password = Yolo::Config::Settings.instance.mail_password @error_formatter = Yolo::Formatters::ErrorFormatter.new @progress_formatter = Yolo::Formatters::ProgressFormatter.new end |
Instance Attribute Details
#account ⇒ Object
The email account to use when sending mail
21 22 23 |
# File 'lib/yolo/notify/email.rb', line 21 def account @account end |
#from ⇒ Object
The email address used in the from feild
15 16 17 |
# File 'lib/yolo/notify/email.rb', line 15 def from @from end |
#password ⇒ Object
The account password to use when sending mail
23 24 25 |
# File 'lib/yolo/notify/email.rb', line 23 def password @password end |
#port ⇒ Object
The port to use when sending mail
19 20 21 |
# File 'lib/yolo/notify/email.rb', line 19 def port @port end |
#server ⇒ Object
An SMTP server
17 18 19 |
# File 'lib/yolo/notify/email.rb', line 17 def server @server end |
#to ⇒ Object
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
82 83 84 |
# File 'lib/yolo/notify/email.rb', line 82 def body(opts) "" end |
#send(opts = {}) ⇒ Object
Sends a nofification email using SMTP
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.account 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.(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.(msg, opts[:from], opts[:to]) @progress_formatter.email_sent(opts[:to]) end else @error_formatter.missing_email_details end end |