maz
Issue with Bamboo Phoenix put_text_layout/put_layout API after upgrading to Phoenix 1.6
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
Most Liked
f0rest8
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:
# email.html.heex
<html>
<head>
...
</head>
<body>
<%= @inner_content %>
</body>
</html>
# email.text.eex
<%= @inner_content %>
# templates/email/example_email_instructions.html.heex
<a href={@url} target="_blank" rel="_noopener"><%= @url %></a>
# templates/email/example_email_instructions.text.eex
<%= @url %>
# mailer.ex
defmodule YourApp.Mailer do
use Bamboo.Mailer, otp_app: :your_app
end
# your_app/example_emails/example_emails_notifier.ex
defmodule YourApp.ExampleEmails.ExampleEmailsNotifier do
use Bamboo.Phoenix, view: YourAppWeb.EmailView
alias YourApp.Mailer
@from_address "hello@example.com"
@reply_to_address "reply@example.com"
def deliver_example_email_instructions(example, url) do
new_email()
|> put_layout({YourAppWeb.LayoutView, :email})
|> to(example.email)
|> from(@from_address)
|> put_header("Reply-To", @reply_to_address)
|> subject("Please confirm your email")
|> render(:example_email_instructions, %{url: url})
|> Mailer.deliver_later()
end
end
And everything works again with heex syntax in my html email templates. ![]()
Popular in Questions
Other popular 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
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









