How to use Phoenix Layout and Views when sending transactional emails using ex_aws and ex_aws_ses?

Hey all,

I’m using ex_aws and ex_aws_ses to send email via the aws api (not smtp). I’m doing it like so:

ExAws.SES.send_email(destination, message, "from-me@example.com", [])
|> ExAws.request()
|> case do
...

The message is basically a map:

%{text: "hello world", html: "<h1>hello world</h1>", subject: "Open me"}

I’d like to use the Phoenix templates/views so that I can write the emails in templates, perhaps templates like welcome_email.html.eex and welcome_email.text.eex. I’ve done a fair bit of searching but and haven’t come across the simple solution. Perhaps I’m not searching for the right terms?

What’s the library or X lines of code that can help me generate those text and html strings that I can send to SES while still having them be in a template and therefore easier to visually parse/edit?

Thank you

You could give Swoosh and phoenix_swoosh a try:

Swoosh also takes care of sending emails via SES, so you don’t have to use ExAws directly.

2 Likes