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, #utm_codes

Instance Method Details

#newsletter(user, newsletter, preview: false) ⇒ 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
# File 'app/mailers/decidim/newsletter_mailer.rb', line 14

def newsletter(user, newsletter, preview: false)
  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