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 8312963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:20:07+00:00 2026-06-08T20:20:07+00:00

I am using the rails 3.2.5 ActionMailer to send plain text mails. Given I

  • 0

I am using the rails 3.2.5 ActionMailer to send plain text mails. Given I have a mail view like this:

message_from_user.text.erb:

Hi <%= @recipient.name %>,

You got the following message from <%= @sender.name %>:

<%= @message %>

When @message is "quotes & ampersands", then the plain text mail contains &quot;quotes &amp; ampersands&quot;. So it seems like rails just treats this as a HTML view and escapes any html in order to prevent cross site scripting. However this is a plain text mail. The extension is .text.erb and ActionMailer detectes this and sets the MIME to text/plain. So I never want to escape any html in it.

I have quite a few mail templates in my application, they are all plain text. I would consider patching all of them to include <%=raw @message%> or <%= @message.html_safe %> bad style – not very DRY.

I tried varios work-arounds that included money patching Erubis. None of them seem to work. I am looking for some patch or config option or anything to disable escaping html for all .text.erb files.

Any help is greatly appreciated!

  • 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-06-08T20:20:10+00:00Added an answer on June 8, 2026 at 8:20 pm

    After some hours of debugging through the Erubis code, I found the following fix. You can just put it into config/initializers/fix_my_mails.rb. I’ve tested this with rails 3.2.7. It may work with other versions.

    module ActionView
      class Template
        module Handlers
          class ERB
            def call(template)
              if template.source.encoding_aware?
                # First, convert to BINARY, so in case the encoding is
                # wrong, we can still find an encoding tag
                # (<%# encoding %>) inside the String using a regular
                # expression
                template_source = template.source.dup.force_encoding("BINARY")
    
                erb = template_source.gsub(ENCODING_TAG, '')
                encoding = $2
    
                erb.force_encoding valid_encoding(template.source.dup, encoding)
    
                # Always make sure we return a String in the default_internal
                erb.encode!
              else
                erb = template.source.dup
              end
    
              self.class.erb_implementation.new(
                erb,
                :trim => (self.class.erb_trim_mode == "-"),
                :escape => template.identifier =~ /\.text/ # only escape HTML templates
              ).src
            end
          end
        end
      end
    end
    

    It just disables HTML entities in every erb file containing .text in the file name.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While using Rails ActionMailer with Multipart Emails I created both: approve_trade_email.html.erb AND approve_trade_email.text.erb I
I have a Rails app (2.3.8) where I send emails using ActionMailer from my
I am trying to send mail using actionmailer on a Rails 3.0.1 application. Here
I'm using Rails to send emails and I just want to send a plain
I'm having trouble sending mail using SMTP from a Rails app. I have a
I'm trying to send mails through rails using Action Mailer and the Googlemail-SMTP-server, but
Using Rails 3.2.0.rc2 and ruby 1.9.3p0 In app/views/requests/_form.html.erb I have the following code for
I'm using ActionMailer for my Rails 2.3.9 application. When I send an email using:
I'm using rails 2 for this app, with ActionMailer, but this is a general
Using Rails 3.2. I have an individual Shop post, and each shop has reviews.

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.