我正在使用Heroku托管用Play Framework 2.2.x(Java)编写的应用程序。此外,我正在使用Mailchimp的Mandrill自动发送电子邮件。

在本地环境中,我可以通过Mandrill发送电子邮件,一切看起来都很好。根据GMail,电子邮件具有以下编码:

MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

但是,在部署到Heroku并执行相同操作时,这些电子邮件看起来是乱码。据GMail称,电子邮件现在具有以下编码:
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit

Heroku上的站点本身看起来不错,并且在UTF8中显示奇特的字符没有任何问题。

我应该提到我正在使用模板和play-easymail(https://github.com/joscha/play-easymail/)来生成电子邮件:即,我使用字符串views.html.emails.myEmailTemplate.render().toString()填充了电子邮件正文。

最佳答案

这在其他地方已被解答:

https://groups.google.com/d/msg/play-framework/Fdr_Fjfbstg/cvbsJNq-SO0J

基本解决方案是从命令行为您的应用程序在JAVA_OPT中设置UTF8编码:

heroku config:add JAVA_OPTS="-Dfile.encoding=UTF8"

10-07 19:19
查看更多