【问题标题】:Elixir Phoenix email render css and layoutElixir Phoenix 电子邮件渲染 css 和布局
【发布时间】:2016-09-24 19:57:16
【问题描述】:

我刚刚写了一个凤凰邮件渲染器。当我通过应用程序发送电子邮件时,外部 css 不会被渲染,并且 mailer.html 布局也没有被拾取。

我在下面做错了吗?

  def invitation_email(conn, to_email) do
    html = View.render_to_string(MailerView, "invitation.html", layout: {LayoutView, "mailer.html"}, conn: conn)
    send_email to: to_email,
               from: "hi@#{conn.host}",
               subject: "Invitation from #{conn.host}!",
               html: html
  end

【问题讨论】:

    标签: elixir phoenix-framework


    【解决方案1】:

    这对我来说看起来不错。您确定不只是不加载css的电子邮件客户端吗?我认为大多数都不会加载外部 css,因此您需要将其放入 <style> 标记中。

    我会在html = ... 行之后放置一个IO.inspect(html),并在调用该函数时检查输出。这包括布局和 css 吗?

    【讨论】:

    【解决方案2】:

    我们在我工作的初创公司也遇到过这个问题,问题可能是样式没有内联。一些电子邮件客户端不支持样式表,因此您必须在每个标签中指定 css 样式。我最近发布了Smoothie,它会自动进行这种内联样式转换,因此 html 模板可以保持干净。此外,它还创建 html 电子邮件的纯文本版本。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多