diff --git a/app/mailers/mailer.rb b/app/mailers/mailer.rb index d69c8016d..b0c0d3541 100644 --- a/app/mailers/mailer.rb +++ b/app/mailers/mailer.rb @@ -120,6 +120,7 @@ class Mailer < ApplicationMailer def newsletter(newsletter, recipient_email) @newsletter = newsletter @email_to = recipient_email + manage_subscriptions_token(User.find_by(email: @email_to)) mail(to: @email_to, from: @newsletter.from, subject: @newsletter.subject) end diff --git a/app/views/mailer/newsletter.html.erb b/app/views/mailer/newsletter.html.erb index 3b45f6105..e28be0eea 100644 --- a/app/views/mailer/newsletter.html.erb +++ b/app/views/mailer/newsletter.html.erb @@ -2,4 +2,15 @@

<%= auto_link_already_sanitized_html wysiwyg(@newsletter.body) %>

+ +

+ <%= sanitize(t("mailers.config.unsubscribe_text", + notifications: link_to( + t("mailers.config.notifications_link"), + edit_subscriptions_url(token: @token), + style: "color: #2895F1; text-decoration: none;" + ), + notification: User.human_attribute_name(:newsletter) + )) %> +

diff --git a/config/locales/en/mailers.yml b/config/locales/en/mailers.yml index 36482beaa..f70669073 100644 --- a/config/locales/en/mailers.yml +++ b/config/locales/en/mailers.yml @@ -8,7 +8,6 @@ en: subject: Someone has commented on your %{commentable} title: New comment config: - manage_email_subscriptions: To stop receiving these emails change your settings in notifications_link: Notifications unsubscribe_text: 'To unsubscribe from these emails, visit %{notifications} and uncheck "%{notification}".' email_verification: diff --git a/config/locales/es/mailers.yml b/config/locales/es/mailers.yml index fa08d810a..0cc21c5b5 100644 --- a/config/locales/es/mailers.yml +++ b/config/locales/es/mailers.yml @@ -8,7 +8,6 @@ es: subject: Alguien ha comentado en tu %{commentable} title: Nuevo comentario config: - manage_email_subscriptions: Puedes dejar de recibir estos emails cambiando tu configuración en notifications_link: Notificaciones unsubscribe_text: 'Para darse de baja de estos emails, puedes entrar en %{notifications} y desmarcar la opción "%{notification}".' email_verification: diff --git a/spec/system/emails_spec.rb b/spec/system/emails_spec.rb index a1e525991..a8de896d0 100644 --- a/spec/system/emails_spec.rb +++ b/spec/system/emails_spec.rb @@ -502,6 +502,10 @@ describe "Emails" do expect(email).to have_subject("This is a different subject") expect(email).to deliver_from("no-reply@consul.dev") expect(email.body.encoded).to include("This is a different body") + expect(email).to have_body_text("To unsubscribe from these emails, visit") + expect(email).to have_body_text( + edit_subscriptions_path(token: user_with_newsletter_in_segment_2.subscriptions_token)) + expect(email).to have_body_text('and uncheck "Receive by email website relevant information"') end end