Search code examples
ruby-on-railsencodingactionmailermailer

Issue on from encoding mailer ruby on rails


I've an issue on the from name when I send mail with the Mailer by Ruby On Rails (Rails 4.1.4).

The from name is not encoded with utf-8 when I put hook inside the mail.

Kévin GUIOT work and return the correct name encoded. Kévin GUIOT [MyCompagny] does't work and return =?UTF-8?Q?K=C3=A9vin_GUIOT_[MyCompagny]_ .

Can u help me please ?

Thanks.

Here is my code:

class TemplateMailer < ActionMailer::Base
  def send_mail(email, subject, content, template_mail)
    from = "Kévin GUIOT [MyCompagny] <[email protected]>"
    mail(to: email, subject: subject, from: from) do |format|
      format.html { render html: content.html_safe }
    end
  end
end

Valid from with correct encoding:

from = "Kévin GUIOT <[email protected]>"

Invalid from with incorrect encoding (with hook):

from = "Kévin GUIOT [MyCompagny] <[email protected]>"

I look my emails with Outlook and the email is sended with a windows machine.


Solution

  • I think you should try

    from = '"Kévin GUIOT [MyCompagny]" '

    according to the rfc https://tools.ietf.org/pdf/rfc5321.pdf