I use Rails 3.1 (3.1.1 RC1) and I configured ActionMailer to use windows-1252 as the default encoding. (External requirement)
This works fine with regular text messages, but as soon as I send HTML letters, the text is converted to UTF-8 again, which leads to distortion of the text.
Here is what I did / found out.
- I set the default encoding:
ActionMailer::Base.default :charset => 'windows-1252' - My .erb template is actually
windows-1252 encoded. - I added the marker
<%# encoding: windows-1252 -%> as the first line of the template. - Mail has a valid content type header:
Content-Type: text/html; charset="windows-1252" Content-Type: text/html; charset="windows-1252"
Here is a snippet of the code that I use to send mail:
mail(:to => ..., :subject => "...") do |format| format.html end
I suspect that somehow, during mail processing, Rails / ActionMailer decides to convert characters to UTF-8. How to change this?
source share