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.
-
.enable_starttls ⇒ Object
Returns the value of attribute enable_starttls.
-
.format ⇒ Object
Returns the value of attribute format.
-
.from_email ⇒ Object
Returns the value of attribute from_email.
-
.from_name ⇒ Object
Returns the value of attribute from_name.
-
.sendmail_args ⇒ Object
Returns the value of attribute sendmail_args.
-
.sendmail_path ⇒ Object
Returns the value of attribute sendmail_path.
-
.server_auth ⇒ Object
Returns the value of attribute server_auth.
-
.server_domain ⇒ Object
Returns the value of attribute server_domain.
-
.server_host ⇒ Object
Returns the value of attribute server_host.
-
.server_password ⇒ Object
Returns the value of attribute server_password.
-
.server_port ⇒ Object
Returns the value of attribute server_port.
-
.server_user ⇒ Object
Returns the value of attribute server_user.
-
.to_email ⇒ Object
Returns the value of attribute to_email.
-
.to_name ⇒ Object
Returns the value of attribute to_name.
Instance Attribute Summary collapse
-
#delivery_method ⇒ Object
Returns the value of attribute delivery_method.
-
#enable_starttls ⇒ Object
Returns the value of attribute enable_starttls.
-
#from_email ⇒ Object
Returns the value of attribute from_email.
-
#from_name ⇒ Object
Returns the value of attribute from_name.
-
#sendmail_args ⇒ Object
Returns the value of attribute sendmail_args.
-
#sendmail_path ⇒ Object
Returns the value of attribute sendmail_path.
-
#server_auth ⇒ Object
Returns the value of attribute server_auth.
-
#server_domain ⇒ Object
Returns the value of attribute server_domain.
-
#server_host ⇒ Object
Returns the value of attribute server_host.
-
#server_password ⇒ Object
Returns the value of attribute server_password.
-
#server_port ⇒ Object
Returns the value of attribute server_port.
-
#server_user ⇒ Object
Returns the value of attribute server_user.
-
#to_email ⇒ Object
Returns the value of attribute to_email.
-
#to_name ⇒ Object
Returns the value of attribute to_name.
Attributes inherited from God::Contact
Instance Method Summary collapse
- #notify(message, time, priority, category, host) ⇒ Object
- #notify_sendmail(mail) ⇒ Object
- #notify_smtp(mail) ⇒ Object
- #valid? ⇒ Boolean
Methods inherited from God::Contact
#arg, defaults, #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.
34 35 36 |
# File 'lib/god/contacts/email.rb', line 34 def delivery_method @delivery_method end |
.enable_starttls ⇒ Object
Returns the value of attribute enable_starttls.
34 35 36 |
# File 'lib/god/contacts/email.rb', line 34 def enable_starttls @enable_starttls end |
.format ⇒ Object
Returns the value of attribute format.
38 39 40 |
# File 'lib/god/contacts/email.rb', line 38 def format @format end |
.from_email ⇒ Object
Returns the value of attribute from_email.
34 35 36 |
# File 'lib/god/contacts/email.rb', line 34 def from_email @from_email end |
.from_name ⇒ Object
Returns the value of attribute from_name.
34 35 36 |
# File 'lib/god/contacts/email.rb', line 34 def from_name @from_name end |
.sendmail_args ⇒ Object
Returns the value of attribute sendmail_args.
34 35 36 |
# File 'lib/god/contacts/email.rb', line 34 def sendmail_args @sendmail_args end |
.sendmail_path ⇒ Object
Returns the value of attribute sendmail_path.
34 35 36 |
# File 'lib/god/contacts/email.rb', line 34 def sendmail_path @sendmail_path end |
.server_auth ⇒ Object
Returns the value of attribute server_auth.
34 35 36 |
# File 'lib/god/contacts/email.rb', line 34 def server_auth @server_auth end |
.server_domain ⇒ Object
Returns the value of attribute server_domain.
34 35 36 |
# File 'lib/god/contacts/email.rb', line 34 def server_domain @server_domain end |
.server_host ⇒ Object
Returns the value of attribute server_host.
34 35 36 |
# File 'lib/god/contacts/email.rb', line 34 def server_host @server_host end |
.server_password ⇒ Object
Returns the value of attribute server_password.
34 35 36 |
# File 'lib/god/contacts/email.rb', line 34 def server_password @server_password end |
.server_port ⇒ Object
Returns the value of attribute server_port.
34 35 36 |
# File 'lib/god/contacts/email.rb', line 34 def server_port @server_port end |
.server_user ⇒ Object
Returns the value of attribute server_user.
34 35 36 |
# File 'lib/god/contacts/email.rb', line 34 def server_user @server_user end |
.to_email ⇒ Object
Returns the value of attribute to_email.
34 35 36 |
# File 'lib/god/contacts/email.rb', line 34 def to_email @to_email end |
.to_name ⇒ Object
Returns the value of attribute to_name.
34 35 36 |
# File 'lib/god/contacts/email.rb', line 34 def to_name @to_name end |
Instance Attribute Details
#delivery_method ⇒ Object
Returns the value of attribute delivery_method.
65 66 67 |
# File 'lib/god/contacts/email.rb', line 65 def delivery_method @delivery_method end |
#enable_starttls ⇒ Object
Returns the value of attribute enable_starttls.
65 66 67 |
# File 'lib/god/contacts/email.rb', line 65 def enable_starttls @enable_starttls end |
#from_email ⇒ Object
Returns the value of attribute from_email.
65 66 67 |
# File 'lib/god/contacts/email.rb', line 65 def from_email @from_email end |
#from_name ⇒ Object
Returns the value of attribute from_name.
65 66 67 |
# File 'lib/god/contacts/email.rb', line 65 def from_name @from_name end |
#sendmail_args ⇒ Object
Returns the value of attribute sendmail_args.
65 66 67 |
# File 'lib/god/contacts/email.rb', line 65 def sendmail_args @sendmail_args end |
#sendmail_path ⇒ Object
Returns the value of attribute sendmail_path.
65 66 67 |
# File 'lib/god/contacts/email.rb', line 65 def sendmail_path @sendmail_path end |
#server_auth ⇒ Object
Returns the value of attribute server_auth.
65 66 67 |
# File 'lib/god/contacts/email.rb', line 65 def server_auth @server_auth end |
#server_domain ⇒ Object
Returns the value of attribute server_domain.
65 66 67 |
# File 'lib/god/contacts/email.rb', line 65 def server_domain @server_domain end |
#server_host ⇒ Object
Returns the value of attribute server_host.
65 66 67 |
# File 'lib/god/contacts/email.rb', line 65 def server_host @server_host end |
#server_password ⇒ Object
Returns the value of attribute server_password.
65 66 67 |
# File 'lib/god/contacts/email.rb', line 65 def server_password @server_password end |
#server_port ⇒ Object
Returns the value of attribute server_port.
65 66 67 |
# File 'lib/god/contacts/email.rb', line 65 def server_port @server_port end |
#server_user ⇒ Object
Returns the value of attribute server_user.
65 66 67 |
# File 'lib/god/contacts/email.rb', line 65 def server_user @server_user end |
#to_email ⇒ Object
Returns the value of attribute to_email.
65 66 67 |
# File 'lib/god/contacts/email.rb', line 65 def to_email @to_email end |
#to_name ⇒ Object
Returns the value of attribute to_name.
65 66 67 |
# File 'lib/god/contacts/email.rb', line 65 def to_name @to_name end |
Instance Method Details
#notify(message, time, priority, category, host) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/god/contacts/email.rb', line 86 def notify(, time, priority, category, host) body = Email.format.call(self.name, arg(:from_email), arg(:from_name), arg(:to_email), arg(:to_name), , time, priority, category, host) case arg(:delivery_method) when :smtp notify_smtp(body) when :sendmail notify_sendmail(body) end self.info = "sent email to #{arg(:to_email)} via #{arg(:delivery_method).to_s}" rescue Object => e applog(nil, :info, "failed to send email to #{arg(:to_email)} via #{arg(:delivery_method).to_s}: #{e.}") applog(nil, :debug, e.backtrace.join("\n")) end |
#notify_sendmail(mail) ⇒ Object
127 128 129 130 131 132 |
# File 'lib/god/contacts/email.rb', line 127 def notify_sendmail(mail) IO.popen("#{arg(:sendmail_path)} #{arg(:sendmail_args)}","w+") do |sm| sm.print(mail.gsub(/\r/, '')) sm.flush end end |
#notify_smtp(mail) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/god/contacts/email.rb', line 104 def notify_smtp(mail) args = [arg(:server_host), arg(:server_port)] if arg(:server_auth) args << arg(:server_domain) args << arg(:server_user) args << arg(:server_password) args << arg(:server_auth) end if arg(:enable_starttls) smtp = Net::SMTP.new(arg(:server_host),arg(:server_port)) smtp.enable_starttls smtp.start(arg(:server_host), arg(:server_user),arg(:server_password), arg(:server_auth)) do |smtp| smtp.(mail,arg(:from_email), arg(:to_email) ) end else Net::SMTP.start(*args) do |smtp| smtp.(mail, arg(:from_email), arg(:to_email)) end end end |
#valid? ⇒ Boolean
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/god/contacts/email.rb', line 70 def valid? valid = true valid &= complain("Attribute 'to_email' must be specified", self) unless arg(:to_email) valid &= complain("Attribute 'delivery_method' must be one of [ :smtp | :sendmail ]", self) unless [:smtp, :sendmail].include?(arg(:delivery_method)) if arg(:delivery_method) == :smtp valid &= complain("Attribute 'server_host' must be specified", self) unless arg(:server_host) valid &= complain("Attribute 'server_port' must be specified", self) unless arg(:server_port) if arg(:server_auth) valid &= complain("Attribute 'server_domain' must be specified", self) unless arg(:server_domain) valid &= complain("Attribute 'server_user' must be specified", self) unless arg(:server_user) valid &= complain("Attribute 'server_password' must be specified", self) unless arg(:server_password) end end valid end |