我想发送一封包含以下设置的电子邮件
def registration_confirmation(user)
recipients user.username + "<" + user.email + ">"
from "Netzwerk Muensterland<[email protected] /cdn-cgi/l/email-protection>"
subject "Vielen Dank für Ihre Registrierung"
body :user => user
content_type "text/html"
end
主题行包含变音符号并且效果很好。
日志告诉我,它的编码如下:
=?utf-8?Q?Vielen_Dank_f=C3=BCr_Ihre_Registrierung?=
但是,如果 user.username 包含变音符号,则电子邮件将不会发送。我正在使用 google apps smtp 服务器。如何为收件人完成这样的编码?
我做到了! ActionMailer 有一个名为 quote_if_necessary 的方法可以解决此类问题。
def registration_confirmation(user)
recipients quote_if_necessary(user.username, "utf-8") + "<" + user.email + ">"
from quote_if_necessary("Netzwerk Münsterland", "utf-8") + " <[email protected] /cdn-cgi/l/email-protection>"
subject "Vielen Dank für Ihre Registrierung"
body :user => user
content_type "text/html"
end
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)