Class: God::Contacts::Email
- Inherits:
-
God::Contact
- Object
- God::Contact
- God::Contacts::Email
- Defined in:
- lib/god/contacts/email.rb
Class Attribute Summary collapse
-
.delivery_method ⇒ Object
Returns the value of attribute delivery_method.
-
.format ⇒ Object
Returns the value of attribute format.
-
.message_settings ⇒ Object
Returns the value of attribute message_settings.
-
.sendmail_settings ⇒ Object
Returns the value of attribute sendmail_settings.
-
.server_settings ⇒ Object
Returns the value of attribute server_settings.
Instance Attribute Summary collapse
-
#email ⇒ Object
Returns the value of attribute email.
Attributes inherited from God::Contact
Instance Method Summary collapse
- #notify(message, time, priority, category, host) ⇒ Object
- #notify_sendmail(mail) ⇒ Object
-
#notify_smtp(mail) ⇒ Object
private.
- #valid? ⇒ Boolean
Methods inherited from God::Contact
#friendly_name, generate, normalize, valid?
Methods included from God::Configurable
#base_name, complain, #complain, #friendly_name, #prepare, #reset
Class Attribute Details
.delivery_method ⇒ Object
Returns the value of attribute delivery_method.
9 10 11 |
# File 'lib/god/contacts/email.rb', line 9 def delivery_method @delivery_method end |
.format ⇒ Object
Returns the value of attribute format.
9 10 11 |
# File 'lib/god/contacts/email.rb', line 9 def format @format end |
.message_settings ⇒ Object
Returns the value of attribute message_settings.
9 10 11 |
# File 'lib/god/contacts/email.rb', line 9 def @message_settings end |
.sendmail_settings ⇒ Object
Returns the value of attribute sendmail_settings.
9 10 11 |
# File 'lib/god/contacts/email.rb', line 9 def sendmail_settings @sendmail_settings end |
.server_settings ⇒ Object
Returns the value of attribute server_settings.
9 10 11 |
# File 'lib/god/contacts/email.rb', line 9 def server_settings @server_settings end |
Instance Attribute Details
#email ⇒ Object
Returns the value of attribute email.
40 41 42 |
# File 'lib/god/contacts/email.rb', line 40 def email @email end |
Instance Method Details
#notify(message, time, priority, category, host) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/god/contacts/email.rb', line 48 def notify(, time, priority, category, host) begin body = Email.format.call(self.name, self.email, , time, priority, category, host) case Email.delivery_method when :smtp notify_smtp(body) when :sendmail notify_sendmail(body) else raise "unknown delivery method: #{Email.delivery_method}" end self.info = "sent email to #{self.email}" rescue => e applog(nil, :info, "failed to send email to #{self.email}: #{e.}") applog(nil, :debug, e.backtrace.join("\n")) end end |
#notify_sendmail(mail) ⇒ Object
84 85 86 87 88 89 |
# File 'lib/god/contacts/email.rb', line 84 def notify_sendmail(mail) IO.popen("#{Email.sendmail_settings[:location]} #{Email.sendmail_settings[:arguments]}","w+") do |sm| sm.print(mail.gsub(/\r/, '')) sm.flush end end |
#notify_smtp(mail) ⇒ Object
private
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/god/contacts/email.rb', line 70 def notify_smtp(mail) args = [Email.server_settings[:address], Email.server_settings[:port]] if Email.server_settings[:authentication] args << Email.server_settings[:domain] args << Email.server_settings[:user_name] args << Email.server_settings[:password] args << Email.server_settings[:authentication] end Net::SMTP.start(*args) do |smtp| smtp. mail, Email.[:from], self.email end end |
#valid? ⇒ Boolean
42 43 44 45 46 |
# File 'lib/god/contacts/email.rb', line 42 def valid? valid = true valid &= complain("Attribute 'email' must be specified", self) if self.email.nil? valid end |