This project is archived and is in readonly mode.

#5075 ✓stale

ActionMailer attachment character set is not properly set

Reported by coffeeaddict_nl | July 9th, 2010 @ 08:10 AM


I am trying to send a generated CSV file by e-mail as an attachment. The contents of this file are utf-8.

ActionMailer is clever enough to render the contents to Base64, but the charset is not set in the headers, which gives grave pain in trying to open or save the file.

I've tried to set the content-type as "text/csv; charset=utf-8" but the "; charset=utf-8" part is neatly gsub'ed of somewhere. When I set the a charset on the attachment (see code below) it is kindly ignored, leading my e-mail client (and the programs thereafter) to believe that the content is latin-1 (or ascii at best)

attachment "text/csv; charset=utf-8" do |a|
  a.filename = "my_lengthy_filename.csv"
  a.body     =

  # even this is ignored
  a.charset  = "utf-8"

It turns out that actionmailer bluntly kills the charset for attachments. This is wrong for text/* type attachments, afaic. And when adding the attachment as a part, the charset is set, but the filename is removed (good behaviour).

I have attached a rather blunt patch that fixes the problem correctly.

PS: This was accidentally posted in Guides before (see:

Comments and changes to this ticket

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:36 PM

    • State changed from “new” to “open”

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:36 PM

    • State changed from “open” to “stale”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>

People watching this ticket