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
和 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)) %>
我不确定这是哪里发生的,字符集$电子邮件的c $ c>标头为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.