I have a Rails app (rails 4.1.11) using Postmark for email delivery. I'm trying to include the user's name in the "To" header of my emails, and I'm having trouble in cases where the name contains a comma, even though I'm putting the name in quotes.
I'm generating the "To" header like so:
address = Mail::Address.new user.email
address.display_name = user.name
address.format
(as suggested in the second answer to Rails ActionMailer - format sender and recipient name/email address). This automatically puts quotes around the name when necessary, so if the user's name is "Sally Smith, MD" the "To" header will be "Sally Smith, MD" <[email protected]>
.
However, when the email is delivered, the "To" header is rendered as "Sally Smith,[email protected]
(at least that's how it shows up in Gmail). When I look at the raw source of the email in Postmark, I see the expected value, To: "Sally Smith, MD" <[email protected]>
. So somewhere between Postmark and Gmail, the header is getting garbled. Am I doing something wrong when formatting the header? Is this a Postmark problem?