ActionMailer非ASCII字符 [英] ActionMailer non-ASCII characters

查看:87
本文介绍了ActionMailer非ASCII字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试发送带有ActionMailer的 text / plain 电子邮件,其中包含非ASCII字符。但是,包含以下内容的电子邮件:

I'm trying to send text/plain emails with ActionMailer that have non-ASCII characters in them. However, an email with the contents:

"This has smart quotes"

在电子邮件(和日志)中显示为:

Displays in emails (and the logs) as:

=E2=80=9CThis has smart quotes=E2=80=9D

和<$ c电子邮件的$ c> Content-Transfer-Encoding 是 quoted-printable 。在视图中,此文本的呈现方式如下:

And the Content-Transfer-Encoding of the email is quoted-printable. In the view, this text is rendered like so:

<%= raw(strip_tags(@message)) %>

我不确定这是哪里发生的,字符集标头为UTF-8。这是Ruby 1.9.3-p194和Rails 3.2.11。

I'm not sure where this is happening, the charset header of the email is UTF-8. This is Ruby 1.9.3-p194 and Rails 3.2.11.

推荐答案

我知道这有点老了,但实际上只是在上周遇到了这个问题,所以我将把我的发现在这里,以防其他人遇到这个问题。

I know this is a bit old, but I actually just ran into this problem last week so I'm going to put my findings here in case anyone else has this question.

ActionMailer取决于邮件gem( https://github.com/mikel/mail )。对于非分段电子邮件,邮件遵循RFC2822。兼容RFC2822,表示仅允许使用US-ASCII字符或1-126 dec范围内的字符。因此,您所看到的是邮件gem检查您的邮件正文并找到8位字符,因此将Content-Transfer-Encoding设置为带引号的可打印格式,将非US-ASCII字符转换为等效的十六进制(E2 80 9C / E2 80 9D | / |左/右双引号分别)。如果要发送非ASCII字符的电子邮件,可以通过将content_transfer_encoding设置为8bit。

ActionMailer depends on the mail gem (https://github.com/mikel/mail). Mail adheres to RFC2822 for non multipart emails. RFC2822 compliant means it ONLY allows US-ASCII characters or characters within the range of 1-126 dec. Therefore, what your seeing is the mail gem checks your message body and finds 8bit chars so it sets Content-Transfer-Encoding to quoted-printable converting non US-ASCII chars to their hex equivalent's (E2 80 9C / E2 80 9D | " / " | left / right double quotes respectively). If you wish to send emails with non ASCII chars you can by setting content_transfer_encoding to 8bit.

mail = Mail.new
mail.transport_encoding = "8bit"
mail.deliver

尽管可能存在邮件服务器谁会拒绝您的电子邮件,因为它包含非US-ASCII字符,因此请谨慎。

Although there may exist mail servers who will deny your email message due to it containing non US-ASCII chars so be ADVISED.

这篇关于ActionMailer非ASCII字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆