Rails ActionMailer encoding

一曲冷凌霜 提交于 2019-12-10 14:54:45

问题


Setup:

Ruby 1.9.2
Rails 3.2.2

I'm having some trouble with the encoding of my emails.

Note: I'm not that familiar with encoding and stuff like that.

When sending an email with ActionMailer, something weird is going on with the html in the email.

All equal(=) signs are getting changed to =3D. Example:

<table border=3D"0" cellpadding=3D"0" cellspacing=3D"0" width=3D"=440">
  <tbody>
    <tr>
      <td height=3D"10">   </td>
    </tr>
  </tbody>
</table>

Special characters looks like this: ä -> ä.

It looks great in local development, but when using SendGrid on production server, special characters don't work.

I'm sure this is because my lack of understanding.

Here's the mail Header:

Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-SMTPAPI: {"filters": {}}

Does it have anything to do with Content-Transfer-Encoding? Or should it be like that?

Maybe it's a problem with SendGrid and not my setup?

An employee at SendGrid told me this: you need to make sure your equals signs are URI-encoded, what does that mean? Thanks in advance!


回答1:


It was not a problem on my side, it was SendGrid. Mails sent through SendGrid with characters like "åäö" does not work in mail clients like yahoo/outlook/MacMail.

After a few hours of support with an employee at SendGrid the problem still persists. They say that the problem is in my setup. I've now switched to mailgun with exactly the same setup and it works great.




回答2:


I solved my problem by adding default 'Content-Transfer-Encoding' => '7bit' to my ActionMailer.

Have a look at the API docs.



来源:https://stackoverflow.com/questions/10543694/rails-actionmailer-encoding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!