Module: Goodmail::Dispatcher
Overview
Responsible for orchestrating the building of the Mail::Message object.
Instance Method Summary collapse
-
#build_message(headers, &block) ⇒ Object
private
Builds the Mail::Message object with HTML and Text parts, wrapped in an ActionMailer::MessageDelivery object.
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 the Mail::Message object with HTML and Text parts, wrapped in an ActionMailer::MessageDelivery object.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/goodmail/dispatcher.rb', line 14 def (headers, &block) # 1. Initialize the Builder builder = Goodmail::Builder.new # 2. Execute the DSL block within the Builder instance builder.instance_eval(&block) if block_given? # 3. Determine the final unsubscribe URL (user-provided) unsubscribe_url = headers[:unsubscribe_url] || Goodmail.config.unsubscribe_url # 4. Determine preheader text (priority: header > config > subject) preheader = headers[:preheader] || Goodmail.config.default_preheader || headers[:subject] # 5. Render the raw HTML body using the Layout raw_html_body = Goodmail::Layout.render( builder.html_output, headers[:subject], unsubscribe_url: unsubscribe_url, preheader: preheader # Pass preheader to layout ) # 6. Slice standard headers for the mailer action mailer_headers = slice_mail_headers(headers) # 7. Build the mail object via the internal Mailer class action. delivery_object = Goodmail::Mailer.( mailer_headers, raw_html_body, nil, # Pass nil for raw_text_body - Premailer generates it unsubscribe_url ) # 8. Return the ActionMailer::MessageDelivery object delivery_object end |