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.
-
#send_mail(payload, args) ⇒ Object
So we can stub out mail sending for tests…
-
#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
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/jackal-mail/smtp.rb', line 38 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 = send_mail(payload, 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
27 28 29 30 31 32 33 |
# File 'lib/jackal-mail/smtp.rb', line 27 def execute() failure_wrap() do |payload| deliver(payload) payload[:data][:mail].delete(:result) job_completed(:mail, payload, ) end end |
#send_mail(payload, args) ⇒ Object
So we can stub out mail sending for tests…
75 76 77 |
# File 'lib/jackal-mail/smtp.rb', line 75 def send_mail(payload, args) Pony.mail(args) end |
#setup(*_) ⇒ Object
Setup the callback
10 11 12 |
# File 'lib/jackal-mail/smtp.rb', line 10 def setup(*_) require 'pony' end |
#valid?(message) ⇒ Truthy, Falsey
Check validity of message
18 19 20 21 22 |
# File 'lib/jackal-mail/smtp.rb', line 18 def valid?() super do |payload| payload.get(:data, :notification_email) end end |