augnustin
Hello,
I’m wondering how to handle emails properly in a phoenix application. There doesn’t appear to be a standard way of doing this, which surprises me.
Coming from the Rails world, my first intention is to bind transaction emails to data actions.
Eg. A Model can be submitted, and this action triggers a ModelEmail.submitted(query).
But if I want to call Model.submit(model) in a console where only the Repo context is Loaded, not the Endpoint, I get:
** (ArgumentError) argument error
(stdlib) :ets.lookup(MyApp.Endpoint, :__phoenix_url__)
(phoenix) lib/phoenix/config.ex:42: Phoenix.Config.cache/3
(vae) web/router.ex:1: MyApp.Router.Helpers.application_url/4
(vae) web/emails/model_email.ex:83: MyApp.ModelEmail.submit/1
because the email makes the use of the Endpoint to get absolute URLs in the email: Routes.model_url(Endpoint, :show, model)
So how should this be done?
IMHO, Sending email should be independent from starting the server, as the only necessary thing is the base URL.
Shouldn’t emails be in a separate process, which can be initialized if desired, and which will receive, either a conn, or an Enpoint or eventually a string like https://example.com so that paths like /path are turned into https://example.com/path?
What are the best practices here? I guess I’m not the first one to have this issue…
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #ai
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 2- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
LostKobrakai
Route helpers also work with
%URI{}structs.augnustin
Hey,
Upping it here, I still have issues.
Though I successfully use:
The same with
static_urldoesn’tAny idea why and how to add images in my email contents?