ActionMailer headers fail encoding with complicated header name #377

ScotterC opened this Issue Apr 3, 2012 · 1 comment

2 participants


Rails 3.2.2
Ruby 1.9.3-p0

class TestMailer < ActionMailer::Base

def test_email
  headers("o:tag" => "Test Email Tag"
  mail :to => ""


fails with:
Encoding::ConverterNotFoundError: code converter not found (UTF-8 to Test Email Tag)
from .../gems/mail-2.4.4/lib/mail/fields/unstructured_field.rb:142:in encode!'
from .../gems/mail-2.4.4/lib/mail/fields/unstructured_field.rb:142:in

Works with
headers("o-tag" => "Test Email Tag"

Can be shown directly in gem environment with {headers("o:tag" => "test tag"); from ''; to ''}


In this particular case, 'o:tag' has an equivalent for Mailgun's library of X-Mailgun-Tag. However, I feel that this should error out more gracefully, but it's certainly not a priority.


Using a colon in the header name is forbidden:

2.2. Header Fields

   Header fields are lines composed of a field name, followed by a colon
   (":"), followed by a field body, and terminated by CRLF.  A field
   name MUST be composed of printable US-ASCII characters (i.e.,
   characters that have values between 33 and 126, inclusive), except

I'll add an ArgumentError when you assign an invalid header name.

@jeremy jeremy closed this in 2bf27fb Jan 27, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment