Class: Nuntius::MailTransport

Inherits:
BaseTransport show all
Defined in:
app/transports/nuntius/mail_transport.rb

Instance Method Summary collapse

Methods inherited from BaseTransport

class_from_name, #kind, #providers

Instance Method Details

#deliver(message) ⇒ Object

We split per email address, to allow easy resends



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/transports/nuntius/mail_transport.rb', line 6

def deliver(message)
  message.html = Inky::Core.new.release_the_kraken(message.html)

  premailer = Premailer.new(message.html, with_html_string: true)
  message.html = premailer.to_inline_css
  message.text = premailer.to_plain_text

  message.request_id = SecureRandom.uuid

  tos = message.to.split(/[\s;,]+/)

  messages = []
  message.to = tos.first
  messages << message

  tos[1..].each do |to|
    # FIXME: Sadly this also duplicates the attachments
    new_message = message.deep_dup
    new_message.to = to
    new_message.attachments = message.attachments if message.attachments.present?

    messages << new_message
  end

  messages.each { |m| super(m) }

  messages.first
end