问题
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
And the Content-Transfer-Encoding
of the email is quoted-printable
. In the view, this text is rendered like so:
<%= raw(strip_tags(@message)) %>
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.
回答1:
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 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
Although there may exist mail servers who will deny your email message due to it containing non US-ASCII chars so be ADVISED.
来源:https://stackoverflow.com/questions/14245335/actionmailer-non-ascii-characters