Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix 'render/2 is undefined' error using Bamboo with Phoenix

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.

like image 698
Blen Avatar asked Mar 26 '19 09:03

Blen


1 Answers

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.

like image 111
Blen Avatar answered Oct 29 '22 23:10

Blen