Class: Jackal::Mail::Smtp
- Inherits:
-
Callback
- Object
- Callback
- Jackal::Mail::Smtp
- Defined in:
- lib/jackal-mail/smtp.rb
Overview
Send mail via SMTP
Instance Method Summary collapse
-
#deliver(payload) ⇒ Object
Deliver mail notification via smtp based on payload contents.
-
#execute(message) ⇒ Object
Process message and send email.
-
#setup(*_) ⇒ Object
Setup the callback.
-
#valid?(message) ⇒ Truthy, Falsey
Check validity of message.
Instance Method Details
#deliver(payload) ⇒ Object
Deliver mail notification via smtp based on payload contents
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/jackal-mail/smtp.rb', line 54 def deliver(payload) payload_conf = payload[:data][:notification_email] begin = payload_conf.fetch(:via_options, config.fetch(:via_options, {})) = Hash[ .map do |k,v| [k.to_sym, v] end ] args = { :to => [payload_conf[:destination]].flatten(1).map{|d| d[:email]}, :from => payload_conf[:origin][:email], :subject => payload_conf[:subject], :via => :smtp, :via_options => } if(payload_conf[:attachments]) args[:attachments] = Hash[*payload_conf[:attachments].map{|k,v|[k.to_s,v]}.flatten(1)] end = payload_conf[:html] ? :html_body : :body args[] = payload_conf[:message] if(args[:via_options][:authentication]) args[:via_options][:authentication] = args[:via_options][:authentication].to_s.to_sym end if(bcc = config.get(:bcc)) args[:bcc] = bcc end result = Pony.mail(args) payload.set(:data, :mail, :result, result) debug "Pony delivery result: #{result.inspect}" rescue => e error "Delivery failed: #{e.class} - #{e}" debug "#{e.class}: #{e}\n#{e.backtrace.join("\n")}" end end |
#execute(message) ⇒ Object
Process message and send email
44 45 46 47 48 49 |
# File 'lib/jackal-mail/smtp.rb', line 44 def execute() failure_wrap() do |payload| deliver(payload) job_completed(:mail, payload, ) end end |
#setup(*_) ⇒ Object
Setup the callback
27 28 29 |
# File 'lib/jackal-mail/smtp.rb', line 27 def setup(*_) require 'pony' end |
#valid?(message) ⇒ Truthy, Falsey
Check validity of message
35 36 37 38 39 |
# File 'lib/jackal-mail/smtp.rb', line 35 def valid?() super do |payload| payload.get(:data, :notification_email) end end |