Giter Site home page Giter Site logo

Comments (13)

romaluca avatar romaluca commented on July 29, 2024 1

Excuse me, in my post i wanted write
lib/shuttertop_web/templates/layout/email.text.eex
Ok if it works to you, i'll check more my code.
Thanks anyway!

from phoenix_swoosh.

princemaple avatar princemaple commented on July 29, 2024

Hi, could you try phoenix_swoosh 1.0.0-rc.0?

from phoenix_swoosh.

princemaple avatar princemaple commented on July 29, 2024

There should be no breaking change and should work with phoenix 1.6

from phoenix_swoosh.

romaluca avatar romaluca commented on July 29, 2024

I upgraded also phoenix_swoosh with:
{:phoenix_swoosh, git: "https://github.com/swoosh/phoenix_swoosh"},
but it the same.
The problem is that the render_body returns nothing and there are no logs.

from phoenix_swoosh.

princemaple avatar princemaple commented on July 29, 2024

Hi @romaluca I'm going to need more info to debug that. Testing with a toy project shows that it works properly with atoms.

Could you setup a minimal reproducible example?

What I got:

lib/test_swoosh/something.ex

defmodule TestSwoosh.Something do
  use Phoenix.Swoosh, view: TestSwoosh.MyView

  def hi do
    new()
    |> subject("what")
    |> to("[email protected]")
    |> from("[email protected]")
    |> render_body(:hi, name: "world")
  end
end

lib/test_swoosh/my_view.ex

defmodule TestSwoosh.MyView do
  use Phoenix.View, root: "lib/test_swoosh/templates"
end

lib/test_swoosh/templates/my/hi.html.eex

<h1>Hello, <%= @name %></h1>

lib/test_swoosh/templates/my/hi.text.eex

Hello, <%= @name %>
iex(1)> TestSwoosh.Something.hi
%Swoosh.Email{
  assigns: %{layout: false, name: "world"},
  attachments: [],
  bcc: [],
  cc: [],
  from: {"", "[email protected]"},
  headers: %{},
  html_body: "<h1>Hello, world</h1>\n",
  private: %{
    phoenix_layout: false,
    phoenix_template: "hi.text",
    phoenix_view: TestSwoosh.MyView
  },
  provider_options: %{},
  reply_to: nil,
  subject: "what",
  text_body: "Hello, world\r\n",
  to: [{"", "[email protected]"}]
}

from phoenix_swoosh.

princemaple avatar princemaple commented on July 29, 2024

render_body should always return the rendered email struct. There is not a case where it would return nothing.

from phoenix_swoosh.

romaluca avatar romaluca commented on July 29, 2024

i found the cause is the layout. I have this:
use Phoenix.Swoosh, view: ShuttertopWeb.UserMailerView, layout: {ShuttertopWeb.LayoutView, :email}

and these files for the common layout:

lib/shuttertop_web/templates/layout/email.html.eex
lib/shuttertop_web/templates/layout/email.txt.eex

If i remove this from the code it works:
layout: {ShuttertopWeb.LayoutView, :email}
I tried also to change the content of the layout files with only:
<%= render @view_module, @view_template, assigns %>
or
<%= @inner_content %>
But it doesn't work.

from phoenix_swoosh.

romaluca avatar romaluca commented on July 29, 2024

I tried the send with iex and there is an error:
[error] %ArgumentError{message: "errors were found at the given arguments:\n\n * 1st argument: not an iodata term\n"}

from phoenix_swoosh.

princemaple avatar princemaple commented on July 29, 2024
lib/shuttertop_web/templates/layout/email.txt.eex

Has this always been txt? Could you try text?

from phoenix_swoosh.

princemaple avatar princemaple commented on July 29, 2024

I added layout and still works. I did get an error, but a different one, if I named it email.txt.eex, though.

lib/test_swoosh/something.ex

defmodule TestSwoosh.Something do
  use Phoenix.Swoosh, view: TestSwoosh.MyView, layout: {TestSwoosh.LayoutView, :email}

  def hi do
    new()
    |> subject("what")
    |> to("[email protected]")
    |> from("[email protected]")
    |> render_body(:hi, name: "world")
  end
end

lib/test_swoosh/layout_view.ex

defmodule TestSwoosh.LayoutView do
  use Phoenix.View, root: "lib/test_swoosh/templates"
end

lib/test_swoosh/templates/layout/email.html.eex

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <%= @inner_content %>
  </body>
</html>

lib/test_swoosh/templates/layout/email.text.eex

TEST <%= @inner_content %>
iex(8)> TestSwoosh.Something.hi
%Swoosh.Email{
  assigns: %{layout: {TestSwoosh.LayoutView, "email.text"}, name: "world"},
  attachments: [],
  bcc: [],
  cc: [],
  from: {"", "[email protected]"},
  headers: %{},
  html_body: "<!DOCTYPE html>\n<html lang=\"en\">\n  <head>\n    <meta charset=\"UTF-8\" />\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n    <title>Document</title>\n  </head>\n  <body>\n<h1>Hello, world</h1>\n\n  </body>\n</html>\n",
  private: %{
    phoenix_layout: {TestSwoosh.LayoutView, :email},
    phoenix_template: "hi.text",
    phoenix_view: TestSwoosh.MyView
  },
  provider_options: %{},
  reply_to: nil,
  subject: "what",
  text_body: "TEST Hello, world\r\n\n",
  to: [{"", "[email protected]"}]
}

from phoenix_swoosh.

princemaple avatar princemaple commented on July 29, 2024

Did you manage to figure out what the issue is?

from phoenix_swoosh.

romaluca avatar romaluca commented on July 29, 2024

Yes, i used the same LayoutView for web pages and email
Before phoenix 1.6 it worked.
I created another LayoutView for email and now it works again.
Thanks

from phoenix_swoosh.

princemaple avatar princemaple commented on July 29, 2024

Interesting. Thanks for the reply.

from phoenix_swoosh.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.