Parent

Files

Class/Module Index [+]

Quicksearch

God::Contacts::Email

Attributes

delivery_method[RW]
format[RW]
from_email[RW]
from_name[RW]
sendmail_args[RW]
sendmail_path[RW]
server_auth[RW]
server_domain[RW]
server_host[RW]
server_password[RW]
server_port[RW]
server_user[RW]
to_email[RW]
to_name[RW]
delivery_method[RW]
from_email[RW]
from_name[RW]
sendmail_args[RW]
sendmail_path[RW]
server_auth[RW]
server_domain[RW]
server_host[RW]
server_password[RW]
server_port[RW]
server_user[RW]
to_email[RW]
to_name[RW]

Public Instance Methods

notify(message, time, priority, category, host) click to toggle source
# File lib/god/contacts/email.rb, line 89
def notify(message, time, priority, category, host)
  body = Email.format.call(self.name, arg(:from_email), arg(:from_name),
                           arg(:to_email), arg(:to_name), message, 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.message}")
  applog(nil, :debug, e.backtrace.join("\n"))
end
notify_sendmail(mail) click to toggle source
# File lib/god/contacts/email.rb, line 121
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) click to toggle source
# File lib/god/contacts/email.rb, line 107
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

  Net::SMTP.start(*args) do |smtp|
    smtp.send_message(mail, arg(:from_email), arg(:to_email))
  end
end
valid?() click to toggle source
# File lib/god/contacts/email.rb, line 73
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

[Validate]

Generated with the Darkfish Rdoc Generator 2.