Add unsubscription link to every message
This commit is contained in:
parent
392536fd7f
commit
9238a9158c
@ -10,10 +10,10 @@ defmodule SendIt.Marketing.MessageNotifier do
|
|||||||
@from_email "newsletter@ptcoffee.com"
|
@from_email "newsletter@ptcoffee.com"
|
||||||
|
|
||||||
def deliver_message(message) do
|
def deliver_message(message) do
|
||||||
message.contacts
|
contacts = message.contacts |> format_recipients()
|
||||||
|> format_recipients()
|
body = message.content |> format_body()
|
||||||
|> dbg()
|
|
||||||
|> deliver(message.subject, message.content)
|
deliver(contacts, message.subject, body)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp deliver(recipients, subject, body) do
|
defp deliver(recipients, subject, body) do
|
||||||
@ -22,10 +22,7 @@ defmodule SendIt.Marketing.MessageNotifier do
|
|||||||
to: recipients,
|
to: recipients,
|
||||||
from: {@from_name, @from_email},
|
from: {@from_name, @from_email},
|
||||||
subject: subject,
|
subject: subject,
|
||||||
html_body:
|
html_body: body
|
||||||
body
|
|
||||||
|> Phoenix.HTML.html_escape()
|
|
||||||
|> Phoenix.HTML.safe_to_string()
|
|
||||||
)
|
)
|
||||||
|> put_provider_option(:recipient_vars, format_recipient_vars(recipients))
|
|> 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})
|
Map.put_new(acc, email, %{name: name})
|
||||||
end)
|
end)
|
||||||
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
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user