Class: Spree::EmailTemplateMailer

Inherits:
BaseMailer
  • Object
show all
Defined in:
app/mailers/spree/email_template_mailer.rb

Overview

Sends an editable email template, rendered with sample data as the editor previews it, so a merchant can see it in a real inbox before publishing.

Instance Method Summary collapse

Methods inherited from BaseMailer

#current_store, #from_address, #mail, #money, #render_in_email_layout, #reply_to_address, #with_store_locale

Instance Method Details

#test_email(store, recipient, key, locale: nil, subject: nil, body: nil, record_id: nil, email_key: nil, branding: {}, mailer_logo_signed_id: nil, mailer_logo_cleared: false) ⇒ Object

Parameters:

  • store (Spree::Store)
  • recipient (String) —

    the email address of the admin who asked for it

  • key (String) —

    the editable template

  • locale (String) (defaults to: nil) —

    a language code, or "any"

  • subject (String, nil) (defaults to: nil) —

    an unsaved subject

  • body (String, nil) (defaults to: nil) —

    an unsaved body

  • record_id (String, nil) (defaults to: nil) —

    the record to build sample data from

  • email_key (String, nil) (defaults to: nil) —

    for the layout or a partial, the email to show it in

  • branding (Hash) (defaults to: {}) —

    unsaved branding values

  • mailer_logo_signed_id (String, nil) (defaults to: nil) —

    the signed id of an unsaved, uploaded email logo

  • mailer_logo_cleared (Boolean) (defaults to: false) —

    whether the email logo is sent as removed



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/mailers/spree/email_template_mailer.rb', line 16

def test_email(store, recipient, key, locale: nil, subject: nil, body: nil, record_id: nil, email_key: nil, branding: {},
               mailer_logo_signed_id: nil, mailer_logo_cleared: false)
  @current_store = store
  email = Spree::EmailTemplates::Preview.new(
    store: store, key: key, locale: locale, subject: subject, body: body, record_id: record_id, email_key: email_key,
    branding: branding, mailer_logo_signed_id: mailer_logo_signed_id, mailer_logo_cleared: mailer_logo_cleared
  ).call

  mail(to: recipient, subject: I18n.t('spree.email_templates.test_email_subject', subject: email.subject)) do |format|
    format.text { render plain: email.text, layout: false }
    format.html { render html: email.html.html_safe, layout: false }
  end
end