I'm trying to send an email using a html email template with Bamboo (and Amazon SES) for my Phoenix/Elixir application
I've managed to get the email sending successfully using Bamboo's |> text_body(message)
method. However I now want to be able to send a html template not just a string so I'm trying to use the render
fn https://hexdocs.pm/bamboo/1.1.0/Bamboo.Phoenix.html#render/3 but I'm experiencing the following error: function MyApp.HtmlEmailView.render/2 is undefined (module MyApp.HtmlEmailView is not available)
. I get no error about my view when I use the text_body
fn.
This is my fn:
def send_test_html_email(to_email_address, subject) do
new_email()
|> from("[email protected]")
|> to(to_email_address)
|> subject(subject)
|> render("email.html")
end
and this is the example fn from the docs:
def html_email do
new_email
|> render("html_email.html")
end
I can't see any difference and as I mentioned before, the rest of the fn was working fine with text_body
as the last line instead of render
.
My expected result is that the email will send without an error. My actual result is the function MyApp.HtmlEmailView.render/2 is undefined (module MyApp.HtmlEmailView is not available)
error.
Thanks Justin Wood and Milan Jaric for your comments.
I was using: use Bamboo.Phoenix, view: MyApp.HtmlEmailView
at the top of my module however the error was being caused as view: MyApp.HtmlEmailView
needed to be view: MyAppWeb.HtmlEmailView
. This has resolved the issue. Thank you for your help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With