Noticed emails are not being sent while testing phx 1.6 update. Oban is reporting this error(truncated). It dies in (phoenix_view 1.0.0) lib/phoenix/view.ex:442: Phoenix.View.render_to_string/3
Oban:
{"{\"at\": \"2021-09-27T23:36:00.880981Z\", \"error\": \"** (ArgumentError) errors were found at the given arguments:\\n\\n * 1st argument: not an iodata term\\n\\n :erlang.iolist_to_binary(%Phoenix.LiveView.Rendered{dynamic: #Function<5.50417823/1 in FaithfulWordWeb.LayoutView.\\\"email.text\\\"/1>, fingerprint: 260608936060549421614240750281229497011, root: false, static: [\\\"\\\", \\\"\\\"]})\\n (phoenix_view 1.0.0) lib/phoenix/view.ex:442: Phoenix.View.render_to_string/3\\n (bamboo_phoenix 1.0.0) lib/bamboo_phoenix.ex:283: Bamboo.Phoenix.render_html_and_text_emails/1\\n (faithful_word 0.1.0) lib/faithful_word/emails.ex:63: FaithfulWord.Emails.one_time_password_request_email/1\\n (oban 2.7.0) lib/oban/queue/executor.ex:209: Oban.Queue.Executor.perform_inline/1\\n (oban 2.7.0) lib/oban/queue/executor.ex:197: Oban.Queue.Executor.perform_inline/1\\n (oban 2.7.0) lib/oban/queue/executor.ex:82: Oban.Queue.Executor.call/1\\n (elixir 1.12.2) lib/task/supervised.ex:90: Task.Supervised.invoke_mfa/2\\n (elixir 1.12.2) lib/task/supervised.ex:35: Task.Supervised.reply/5\\n (stdlib 3.15.1) proc_lib.erl:226: :proc_lib.init_p_do_apply/3\\n\", \"attempt\": 1}"
dependencies:
bamboo 2.2.0
bamboo_phoenix 1.0.0
oban 2.7.0
phoenix 1.6.0
phoenix_ecto 4.3.0
phoenix_html 3.0.0 RETIRED!
(security) The :class attribute in content_tag and in class={@class} for HEEx is not escaped against XSS
phoenix_live_dashboard 0.5.2
phoenix_live_reload 1.3.3
phoenix_live_session 0.1.3
phoenix_live_view 0.16.4
phoenix_pubsub 2.0.0
phoenix_view 1.0.0
This is the line where it trips-up:
defp base_email do
new_email()
|> from(@sender_no_reply)
# Set default layout
|> put_html_layout({FaithfulWordWeb.LayoutView, "email.html"})
# Set default text layout
|> put_text_layout({FaithfulWordWeb.LayoutView, "email.text"}) ## here
end
checked the docs here: https://hexdocs.pm/bamboo_phoenix/Bamboo.Phoenix.html
and there is another API put_layout()
so I tried it but same issue … any suggestions?
defp base_email do
new_email()
|> from(@sender_no_reply)
|> put_layout({FaithfulWordWeb.LayoutView, :email})
end
What extension does email.html has, .eex, .leex, or .heex? I think it needs to be .eex to be rendered directly to iodata or string, the other two would be rendered to Phoenix.LiveView.Rendered.t which seems to be the cause of the problem.
Yeah thanks that is a good catch. I changed the extensions for both those files to .heex but I didn’t convert the contents from legacy eex to heex when I did that.
I had a similar thing occur when updating my emails being sent with Bamboo to .heex. But I don’t believe it’s anything too wrong with Bamboo. I have email.html.heex set and you need to leave the email.text.eex as is.
Then your corresponding templates for html emails are heex syntax and your text emails are as is. I use the put_layout(AppWeb.LayoutView, :email).
I should also mention I use the render function too. On my phone so I’m not sure of the arity/specifics, but you call that with the atom for your email templates (it renders both the html and text).
@maz - here’s an example of how I’m doing it with Bamboo and .heex:
Thanks for the detailed reply! Emails are working again but I left everything as .eex.
When I made email.html.eex → email.html.heex and applied changes similar to yours, I started going down a really bad rabbit hole when I started changing the *.html.eex → *.html.heex.
The Eex parser would not tell me which file there was a failure in(“nofile”):
I have a large number of templates so there was no easy way for me to determine which file and which specific char was failing. It was like trying to find a needle in a haystack.
So unless there is another solution, I will let sleeping dogs lie and leave everything as .eex
Looking at what you shared, I would probably go 1 file at a time. So, change for instance the password_reset.en.html.eex to .heex and update it’s html syntax and see if that works, that way I know which one I’m working on.
Then, from what you shared, my guess is you have another template that’s being used in the file that you might be working on, like _user_menu.html.eex for example. What that means is then that if that “shared template” has improper .heex format it will throw an error because it’s being rendered now in your .heex that you specifically changed.
So, you would need to make sure you updated all of those to fit your .heex too. That would be my approach and guess based on what you just shared.
Edit: sorry again on my phone. Looking again at the template section, I think I might be misreading it. But the gist of my thought I think still applies just maybe not the example with the _user_menu.html.eex.
Edit: one last thought is checking too that your purge (if using something like Tailwind) is updated to match the new file endings in .heex.