Class: Decidim::NewsletterMailer

Inherits:
ApplicationMailer show all
Includes:
NewslettersHelper
Defined in:
app/mailers/decidim/newsletter_mailer.rb

Instance Method Summary collapse

Methods included from NewslettersHelper

#custom_url_for_mail_root, #parse_interpolations

Methods included from OrganizationHelper

#current_organization_name, #organization_colors, #organization_description_label, #organization_name

Methods included from TranslatableAttributes

#default_locale?

Methods included from SanitizeHelper

#decidim_escape_translated, #decidim_html_escape, #decidim_sanitize, #decidim_sanitize_admin, #decidim_sanitize_editor, #decidim_sanitize_editor_admin, #decidim_sanitize_newsletter, #decidim_sanitize_translated, #decidim_url_escape, included

Instance Method Details

#newsletter(user, newsletter, preview = nil) ⇒ Object



11
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 'app/mailers/decidim/newsletter_mailer.rb', line 11

def newsletter(user, newsletter, preview = nil)
  return if user.email.blank?

  @organization = user.organization
  @newsletter = newsletter
  @user = user
  @preview = preview

  @custom_url_for_mail_root =
    if @preview
      "#"
    elsif Decidim.config.track_newsletter_links
      custom_url_for_mail_root(@organization, @newsletter.id)
    end
  @encrypted_token = Decidim::NewsletterEncryptor.sent_at_encrypted(@user.id, @newsletter.sent_at)

  with_user(user) do
    uninterpolated_subject =
      @newsletter.subject[I18n.locale.to_s].presence || @newsletter.subject[@organization.default_locale]

    @subject = parse_interpolations(uninterpolated_subject, user, @newsletter.id)

    mail(to: "#{user.name} <#{user.email}>", subject: @subject)
  end
end