bug in 3.2.14 related to multipart mail sending using a format block

Dear Rails Core,

I believe I have identified a bug related to passing a format block to a mail() method call (I identified this on Rails 3.2.14, have not tried other versions of Rails). Contrary to what is documented here http://guides.rubyonrails.org/action_mailer_basics.html, I was not able to successfully pass a format block to my mail method call like so:
mail(:to => @user.email, :subject => email_subject) do |format|
format.html { render layout: nil}
format.text { render }
When passing a format block to mailer, this makes Gmail (web-based) and my OS X Mail client display the Plain-text alternative when it should be displaying the HTML version. In Gmail web interface it opens to the Plain text alternative, and if you “switch to Plain text” you actually see the HTML version which is pretty odd. (Gmail does not give you an option to view the alternative)
Oddly, the very same mail mail message does display correctly when sent to an @mailinator.com address (which only displays the HTML).
When you don’t pass a format block to the mailer call, like so:
mail(:to => @user.email, :subject => email_subject)
… the mail is displayed correctly in Gmail.
I examined line-by-line the raw source of the two mail messages, and I noticed this:

  1. In the working version (with a format block in my code), the plain text appears first above the HTML alternative. (I don’t think this should matter at all, I’m just noting it in case it is significant).
  2. Within the text/html section of the message, there are some headers. (You see this below the “mime part boundary” that looks something like ----==_mimepart_52ec14fb61916_a3ff60f2ed3f4146dd
    For the non-working version (with a format block), I see this header:
    Content-Transfer-Encoding: 7bit
    For the working version (without a format block), I see this header instead:
    Content-Transfer-Encoding: quoted-printable

I’m not sure if either one is acceptable in the RFC standard, nor I have looked into the Rails code itself. However, obviously we cannot send emails that don’t work in Gmail, so for us we need to use a workaround. (In my case I was able to easily remove the format block because all I was doing was setting the layout, which I could set globally on the mailer object instead.)

Obviously the work-around is OK for me, but I thought I’d send this note as documentation for the archive.


Jason FB

What I meant to write here was “In OS X Mail interface it opens to the Plain text alternative and if you ‘switch to Plain text’ you see the HTML version”. In Gmail it also shows the Plain-text version when it should be showing the HTML version, and there is no option to switch to any other version (except Raw source)