Module: Goodmail::Dispatcher

Extended by:
Dispatcher
Included in:
Dispatcher
Defined in:
lib/goodmail/dispatcher.rb

Overview

Responsible for orchestrating the building of the Action Mailer delivery.

Instance Method Summary collapse

Instance Method Details

#build_message(headers, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Builds an ActionMailer::MessageDelivery with HTML and text parts.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/goodmail/dispatcher.rb', line 12

def build_message(headers, &block)
  headers = headers.dup
  render_config_overrides = render_config(headers)

  Goodmail.with_config(render_config_overrides) do
    parts = Goodmail.render(headers, &block)

    # ActionMailer::MessageDelivery processes this mailer action lazily and
    # `deliver_later` serializes only action arguments, so pass already
    # rendered strings and plain attachment descriptor hashes into the action.
    # Sources:
    # - MessageDelivery laziness:
    #   https://github.com/rails/rails/blob/debbd18c562df17d01944c475e9291d927910b58/actionmailer/lib/action_mailer/message_delivery.rb#L22-L35
    # - deliver_later serializes mailer action arguments:
    #   https://github.com/rails/rails/blob/debbd18c562df17d01944c475e9291d927910b58/actionmailer/lib/action_mailer/message_delivery.rb#L142-L155
    Goodmail::Mailer.compose_message(
      slice_mail_headers(headers),
      parts.html,
      parts.text,
      resolved_unsubscribe_url(headers),
      parts.attachments
    )
  end
end