Rails:如何向包含变音符号的收件人发送电子邮件? [英] Rails: How to send emails to a recipient containing umlauts?
本文介绍了Rails:如何向包含变音符号的收件人发送电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过以下设置发送电子邮件
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?=
但是,如果user.username包含变音符号,则电子邮件将不会发送.我正在使用Google Apps SMTP服务器.如何为收件人完成这样的编码?
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?
推荐答案
我成功了!有一个名为quote_if_necessary的ActionMailer方法可以解决此类问题.
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
这篇关于Rails:如何向包含变音符号的收件人发送电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文