Class: Eye::Notify::Mail

Inherits:
Eye::Notify show all
Defined in:
lib/eye/notify/mail.rb

Constant Summary

Constants inherited from Eye::Notify

TIMEOUT, TYPES

Instance Method Summary collapse

Methods inherited from Eye::Notify

#async_notify, get_class, #initialize, #logger_sub_tag, #message_body, #message_subject, notify, #notify, register, requires, validate!

Methods included from Dsl::Validation

included

Constructor Details

This class inherits a constructor from Eye::Notify

Instance Method Details

#executeObject



23
24
25
# File 'lib/eye/notify/mail.rb', line 23

def execute
  smtp
end

#messageObject



38
39
40
41
42
43
44
45
46
# File 'lib/eye/notify/mail.rb', line 38

def message
  h = []
  h << "From: #{from_name} <#{from_mail || user}>" if from_mail || user
  h << "To: <#{contact}>"
  h << "Subject: #{message_subject}"
  h << "Date: #{msg_at.httpdate}"
  h << "Message-Id: <#{rand(1_000_000_000).to_s(36)}.#{$$}.#{contact}>"
  "#{h * "\n"}\n#{message_body}"
end

#smtpObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/eye/notify/mail.rb', line 27

def smtp
  args = [host, port, domain, user, password, auth]
  debug { "called smtp with #{args}" }
  smtp = Net::SMTP.new host, port
  smtp.enable_starttls if starttls

  smtp.start(domain, user, password, auth) do |s|
    s.send_message(message, from_mail || user, contact)
  end
end