martins

martins

Can't get Swoosh to use the template I'm specifying.

Hi,

I´m trying to send email using Phoenix.Swosh, but I get this error message that I don´t really understand.

This is how I send the mail:

      MyCompany.UserEmail.mail_requesting_signature(%{
        contract: contract,
        current_user: sender
      })
      |> MyCompany.Mailer.deliver()

defmodule MyCompany.UserEmail do
  use Phoenix.Swoosh,
    template_root: "lib/MyCompany_web/templates/emails/",
    template_path: "requesting_signature"


  def mail_requesting_signature(%{
        contract: contract,
        current_user: current_user
      }) do
    sender_email = extract_string(current_user.email)
    recipient_email = contract.client.email
    recipient_name = "John Doe"

    new()
    |> to({recipient_email, recipient_name})
    |> from({"MyCompany", "no-reply@MyCompany.no"})
    |> subject("#{sender_email} has invited you to sign a contract")
    |> render_body(
      "requesting_signature.html.heex",
      %{
        username: user.email,
        title: contract.title,
        content: contract.content,
      }
    )
  end
end
 ** (Phoenix.Template.UndefinedError) Could not render "mail_template.html.heex" for MyCompany.UserEmail, please define a matching clause for render/2 or define a template at "lib/MyCompany_web/templates/emails/mail_template/*". The following templates were compiled:

 * mail_template.html

 Assigns:

 %{title: "Pacocha Group", username: "user.email", email: %Swoosh.Email{subject: "merlin_gibson@rempel.org has invited you to sign a contract", from: {"MyCompany", "no-reply@MyCompany.no"}, to: [{"deion2076@balistreri.biz", "John Doe"}], cc: [], bcc: [], text_body: nil, html_body: nil, attachments: [], reply_to: nil, headers: %{}, private: %{phoenix_view: MyCompany.UserEmail, phoenix_template: "mail_template.html.heex", phoenix_layout: false}, assigns: %{title: "Pacocha Group", layout: false, username: "user.email", content: "Vero repellendus velit in nihil enim voluptatem rerum est et. Voluptate vel aspernatur et accusantium mollitia ea reprehenderit expedita aut. Et debitis veritatis dolore tenetur cumque et ut. Expedita itaque maxime dolorem autem. Perspiciatis eum dolores rerum delectus dolores commodi sunt.", sign_url: "http://localhost:4000/contracts/f46b280d-e05e-418b-805a-079f473db7ae/sign"}, provider_options: %{}}, content: "Vero repellendus velit in nihil enim voluptatem rerum est et. Voluptate vel aspernatur et accusantium mollitia ea reprehenderit expedita aut. Et debitis veritatis dolore tenetur cumque et ut. Expedita itaque maxime dolorem autem. Perspiciatis eum dolores rerum delectus dolores commodi sunt."}

 Assigned keys: [:title, :username, :email, :content,]

The template:
lib/quantik_web/templates/emails/requesting_signature/requesting_signature.html.heex

<div>
  <h1>Document to be signed</h1>
  <h1>Welcome to MyCompany, <%= @username %>!</h1>
  <pre> Please read the document below: </pre>
  <h2><%= @title %></h2>
  <pre> <%= @content %> </pre>
</div>

Most Liked

martins

martins

Yes, that was it! I removed the .heex part of the template name, and it worked.
Thanks, @linusdm :blush:

patch

     |> render_body(
-      "requesting_signature.html.heex",
+      "requesting_signature.html",
       %{

Where Next?

Popular in Questions Top

openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
kostonstyle
Hi all I want to have a unix time, from the current time plus 1 hour. DateTime.now + 1 hour How to get it in elixir? Thanks
New
Codball
Mix format works fine if run from the cmd. I’ve followed this to facilitate the implementation into VSC which involves downloading an ext...
New

Other popular topics Top

JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

We're in Beta

About us Mission Statement