Sending emails with Ash
Does Ash have a wrapper for Sending emails or a recommended way to send transactional emails e.g. Confirm Account?
16 Replies
No wrapper for it, but generally speaking you will want to implement them by using
notifiers
.
Ash takes care of ensuring that notifications are only sent after the transaction completes, so there are no timing issues.
https://ash-hq.org/docs/guides/ash/latest/topics/notifiersCool, lets say I have an email that should happen without changes to the database e.g. a reminder from an Oban job can you programatically do that with notifiers?
You can, if you do something like this:
and then you can hook into it from a notifier.
ah ok, make a changeset that dosen't make any changes
Yep. In that case its a manual action, but if the changeset has no changes it won't update the record also
the manual action doesn't hit the database unless you do something in the manual action to do so.
Thanks Zach
Perfect timing, I just needed to do this too.
Greenfielding w/ Ash is such a better experience than all the boilerplate. 😄
How are you actually sending the emails? I wanted to try render Phoenix views
GitHub
GitHub - swoosh/swoosh: Compose, deliver and test your emails easil...
Compose, deliver and test your emails easily in Elixir - GitHub - swoosh/swoosh: Compose, deliver and test your emails easily in Elixir
GitHub
GitHub - swoosh/phoenix_swoosh: Swoosh <3 Phoenix
Swoosh <3 Phoenix. Contribute to swoosh/phoenix_swoosh development by creating an account on GitHub.
Does that work with CSS e.g. tailwindcss or does it still need premailing?
I use Swoosh Phoenix + premail for one app. I don't use Tailwind in that one. Email is actually pretty tricky as far as what CSS is supported in the various clients.
In another app, I use MJML, a special framework for ultimate CSS compatibility in Emails, got the idea from these posts.
https://akoutmos.com/post/mjml-template-compliation/
https://medium.com/swlh/using-mjml-in-elixir-phoenix-ca27050ff26f
My.Thoughts v1
Crafting Beautiful Emails in Elixir Using MJML
Compile MJML->HTML->EEx using a Rust NIF and send your Phx.Gen.Auth notifications via Swoosh
Medium
Using MJML in Elixir & Phoenix
How to create responsive HTML emails for your Phoenix app with ease
W/ emphasis on the first on, I went w/ the pre-rendered on the server way of doing it.
Awesome, thanks 🙌🏼
I tried premailx with tailwind but never got it to work unless I manually coppied the CSS into an inline style tag
One suggestion: Make an effort to do an equally nice text Email body. Always good to have a fallback, and an option for odd ducks like me that use a terminal Email client.
TableRex
is a good lib for generating nice ASCII tables.Yeah, I don't plan to send many emails but I would like the text ones to be nice and at the least functional
although the client base for this app I presume it will mostly be GUI clients
Yeah, safe assumption.