Class: DAF::EmailAction

Inherits:
Action
  • Object
show all
Defined in:
lib/daf/actions/email_action.rb

Overview

An action that sends an email based on parameters

Instance Method Summary collapse

Methods inherited from Action

#activate

Methods included from Configurable

included

Instance Method Details

#format_email(to, from, subject, body) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/daf/actions/email_action.rb', line 24

def format_email(to, from, subject, body)
  <<TEXT
  From: #{from}
  To: #{to}
  Subject: #{subject}

  #{body}
TEXT
end

#invokeObject



14
15
16
17
18
19
20
21
22
# File 'lib/daf/actions/email_action.rb', line 14

def invoke
  message = format_email(@to.value, @from.value,
                         @subject.value, @body.value)
  port = self.port.valid? ? self.port.value : 25
  Net::SMTP.start(@server.value, port) do |smtp|
    smtp.send_message(message, @from.value, @to.value)
  end
  true
end