Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6769703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:13:30+00:00 2026-05-26T15:13:30+00:00

So, Rails has the wonderful capability of sending plaintext emails alongside HTML emails. You

  • 0

So, Rails has the wonderful capability of sending plaintext emails alongside HTML emails.

You just put up a .text.erb alongside your .html.erb. I put up an application to this effect here: https://github.com/cairo140/rails-email-test. Just download and run. Visit the homepage and check the logs.

Here’s the output:

Sent mail to test@test.com (19ms)
Date: Tue, 01 Nov 2011 14:48:59 -0400
From: test@test.com
To: test@test.com
Message-ID: <4eb03f1b7403b_178858111fcc060bd@Steven-Xus-Macbook-Pro.local.mail>
Subject: test
Mime-Version: 1.0
Content-Type: multipart/alternative;
 boundary="--==_mimepart_4eb03f1b708ce_178858111fcc057a4";
 charset=UTF-8
Content-Transfer-Encoding: 7bit



----==_mimepart_4eb03f1b708ce_178858111fcc057a4
Date: Tue, 01 Nov 2011 14:48:59 -0400
Mime-Version: 1.0
Content-Type: text/plain;
 charset=UTF-8
Content-Transfer-Encoding: 7bit
Content-ID: <4eb03f1b72b72_178858111fcc058ce@Steven-Xus-Macbook-Pro.local.mail>

Unescaped: &

Escaped: &amp;

ERB: &amp;


----==_mimepart_4eb03f1b708ce_178858111fcc057a4
Date: Tue, 01 Nov 2011 14:48:59 -0400
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit
Content-ID: <4eb03f1b73784_178858111fcc05933@Steven-Xus-Macbook-Pro.local.mail>

<!doctype html>
<html>
  <head>
    <title>test</title>
  </head>
  <body>
    <ul>
      <li>Unescaped: &</li>
      <li>Escaped: &amp;</li>
      <li>ERB: &amp;</li>
    </ul>
  </body>
</html>


----==_mimepart_4eb03f1b708ce_178858111fcc057a4--

Now, this is the text view (app/views/application_mailer/index.text.erb):

$ cat app/views/application_mailer/index.text.erb 
Unescaped: &

Escaped: &amp;

ERB: <%= "&" %>

As you can see, the resulting text email is overescaped.

Is there any way to prevent this?


Further clarification:

If you surpress the HTML email and just send the text, you get this in the email client (I’m using Gmail):

email body

As you can see, the third line is overescaped.

Obviously, you can call html_safe on every string, or raw on every ERB tag, but surely, there must be a way to get Rails/Erubis to recognize the fact that it’s in a text email and escape accordingly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:13:30+00:00Added an answer on May 26, 2026 at 3:13 pm

    There’s a thread in rails’ lighthouse discussing the problem and a monkey patch trying to fix it too. Try dropping this into initializers and give it a try.

    # fix_erubis_non_escape_sequence.rb
    module ActiveSupport
      class SafeBuffer < String
        alias safe_append= safe_concat
      end
    end
    
    module ActionView
      class Template
        module Handlers
          class Erubis < ::Erubis::Eruby
            def add_expr_escaped(src, code)
              if code =~ BLOCK_EXPR
                src << "@output_buffer.safe_append= " << code
              else
                src << "@output_buffer.safe_concat((" << code << ").to_s);"
              end
            end
          end
        end
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My Rails application has a number of tasks which are offloaded into background processes,
We are developing an application that has an iPhone client, and a Rails server.
Rails has beautiful documentation on their guides and their website: http://guides.rubyonrails.org/association_basics.html I am taking
I'm just wondering if rails has any inbuilt way of determining the correct http
Rails has a means to update its presentation layer via js files and js.erb
This code just works fine, but I'm sure rails has a better way to
I know that Rails has sorting methods built into ActiveRecord, but I am just
Rails has a nice idiom that makes it easy for you to have a
Rails has no way of creating foreign keys in migrations (there are plugins to
Rails has the rest autho plugin which works well but is there a solution

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.