Add unsubscription link to every message

This commit is contained in:
Nathan Chapman 2024-11-19 09:59:50 -07:00
parent 392536fd7f
commit 9238a9158c

View File

@ -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}
<br />
<br />
<hr />
<p>
<strong>Unsubscribe</strong><br />
If you no longer wish to receive our emails, you can <a href="#{url}?%recipient%">unsubscribe here</a>.
</p>
"""
end
end