Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've spent a good chunk of the last couple of days on this now and it seems there is no great solution. It is possible to render the message explicitly and then pass the result through Premailer, but it gets messy in combination with multipart emails and HTML layouts and if the template uses some other encoding than ASCII-8BIT.</p> <p>In a straight HTML email without multiparts and assuming an ASCII-8BIT encoded template, this works for me:</p> <pre><code>def some_email recipients "Reciever &lt;reciever@example.com&gt;" from "Sender &lt;sender@example.com&gt;" subject "Hello" content_type "text/html" message = render_message("some_email", { }) # second argument is a hash of locals p.body = Premailer.new(message, with_html_string: true).to_inline_css end </code></pre> <p>However, if the template is encoded with some other encoding than ASCII-8BIT, Premailer destroys all non-ASCII characters. There is a fix merged into the Premailer repo, but no version has been released since. Using the latest revision and calling <code>Premailer.new(message, with_html_string: true, input_encoding: "UTF-8").to_inline_css</code> or similar should work. The merge commit is <a href="https://github.com/alexdunae/premailer/commit/5f5cbb4ac181299a7e73d3eca11f3cf546585364" rel="nofollow">https://github.com/alexdunae/premailer/commit/5f5cbb4ac181299a7e73d3eca11f3cf546585364</a>.</p> <p>In the case of multipart emails I haven't really gotten ActionMailer to use the correct content types internally for rendering the templates. This results in the implicit typing via template file names not working and, as a result, layouts being incorrectly applied to text versions. A workaround for this would be to explicitly use no layout for the text version, resulting in something like this (note the template names):</p> <pre><code>def some_multipart_email recipients "Reciever &lt;reciever@example.com&gt;" from "Sender &lt;sender@example.com&gt;" subject "Hello" content_type "text/html" part "text/html" do |p| message = render_message("some_email_html", { }) p.body = Premailer.new(message, with_html_string: true).to_inline_css end part "text/plain" do |p| p.content_type = "text/plain" p.body = render(file: "some_email_text", body: { }, layout: false) end end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload