简体   繁体   English

如何使用 actionmailer 发送带有口音的电子邮件

[英]How to use send an email with accents using actionmailer

My environment.rb is like this:我的environment.rb是这样的:

ActionMailer::Base.default_charset = "iso-8859-1"

which should be enough for accents, but here is how the message's subject is being sent:这对于重音应该足够了,但这里是消息主题的发送方式:

Convite para participação de projeto邀请参与项目

Does anyone know what I have to do to fix it?有谁知道我必须做些什么来解决它?

Is your data in iso-8859-1?你的数据是iso-8859-1吗? From the look of the error example, it seems to be two bytes per character (note the repetition of Ã).从错误示例的外观来看,每个字符似乎是两个字节(注意 Ã 的重复)。 Since 8859-1 uses 1 byte per character, my guess is that your data is in utf-8 format.由于 8859-1 每个字符使用 1 个字节,我猜你的数据是 utf-8 格式。

Also check that your db is not doing any conversions on data going in or out.还要检查您的数据库是否没有对输入或输出的数据进行任何转换。

I urge you to use unicode / utf-8 everywhere--database, html, emails, etc. It's what all of the kool-kids are using these days.我敦促你在任何地方使用 unicode / utf-8——数据库、html、电子邮件等。这是所有 kool-kids 现在都在使用的。 8859-1 is so last century! 8859-1就是上个世纪!

Regarding emails关于电子邮件

  config.action_mailer.default_charset = "utf-8"

is what I use.是我使用的。

Just remove your setting and let Rails do the work using the default charset, UTF-8.只需删除您的设置,让 Rails 使用默认字符集 UTF-8 来完成工作。

I work with emails and special characters all the time, there's no need to perform any kind of conversion or setting, at least not on Rails 3. As long as your strings contains the right characters, you'll be fine.我一直在处理电子邮件和特殊字符,不需要执行任何类型的转换或设置,至少在 Rails 3 上不需要。只要您的字符串包含正确的字符,就可以了。

Just make sure the encoding error is not ocurring when reading the data from your database.只需确保从数据库读取数据时不会发生编码错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM