From 9238a9158c7c6e572a708428b89b825c6f3f2a0a Mon Sep 17 00:00:00 2001 From: Nathan Chapman Date: Tue, 19 Nov 2024 09:59:50 -0700 Subject: [PATCH] Add unsubscription link to every message --- lib/send_it/marketing/message_notifier.ex | 34 +++++++++++++++++------ 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/lib/send_it/marketing/message_notifier.ex b/lib/send_it/marketing/message_notifier.ex index f4a7279..65aeaf7 100644 --- a/lib/send_it/marketing/message_notifier.ex +++ b/lib/send_it/marketing/message_notifier.ex @@ -10,10 +10,10 @@ defmodule SendIt.Marketing.MessageNotifier do @from_email "newsletter@ptcoffee.com" def deliver_message(message) do - message.contacts - |> format_recipients() - |> dbg() - |> deliver(message.subject, message.content) + contacts = message.contacts |> format_recipients() + body = message.content |> format_body() + + deliver(contacts, message.subject, body) end defp deliver(recipients, subject, body) do @@ -22,10 +22,7 @@ defmodule SendIt.Marketing.MessageNotifier do to: recipients, from: {@from_name, @from_email}, subject: subject, - html_body: - body - |> Phoenix.HTML.html_escape() - |> Phoenix.HTML.safe_to_string() + html_body: body ) |> put_provider_option(:recipient_vars, format_recipient_vars(recipients)) @@ -48,4 +45,25 @@ defmodule SendIt.Marketing.MessageNotifier do Map.put_new(acc, email, %{name: name}) end) end + + defp format_body(content) do + content + |> add_unsubscription() + end + + defp add_unsubscription(content) do + url = url(~p"/subscription") + + """ + #{content} +
+
+ +
+

+ Unsubscribe
+ If you no longer wish to receive our emails, you can unsubscribe here. +

+ """ + end end