Rails: How to send emails to a recipient containin

2019-07-07 00:48发布

I'ld like to send an email with the following setup

def registration_confirmation(user)
  recipients    user.username + "<" + user.email + ">"
  from          "Netzwerk Muensterland<mailer@netzwerkmuensterland.de>"
  subject       "Vielen Dank für Ihre Registrierung"
  body          :user => user
  content_type  "text/html"
end

The subject line contains an umlaut and works fine. The log says me, it was encoded like this:

=?utf-8?Q?Vielen_Dank_f=C3=BCr_Ihre_Registrierung?=

But, if the user.username contains umlauts, the email will not send. I am using a google apps smtp server. How do I accomplish a encoding like this for recipients?

1条回答
beautiful°
2楼-- · 2019-07-07 01:22

I made it! There is a ActionMailer method called quote_if_necessary which takes care of this kind of problem.

def registration_confirmation(user)
  recipients    quote_if_necessary(user.username, "utf-8") + "<" + user.email + ">"
  from          quote_if_necessary("Netzwerk Münsterland", "utf-8") + " <mailer@netzwerkmuensterland.de>"
  subject       "Vielen Dank für Ihre Registrierung"
  body          :user => user
  content_type  "text/html"
end
查看更多
登录 后发表回答