特殊字符的编码不适用于 sendgrid 模板的电子邮件主题

Abd*_*eeb 2 ruby-on-rails sendgrid sendgrid-ruby sendgrid-templates

我一直在使用 sendgrid-ruby gem 发送电子邮件。电子邮件的主题没有正确解码特殊字符。例如。为电子邮件发送此主题会How's it going在实际电子邮件中转换为此主题How's it going

我曾尝试将字符串编码为不同的格式,例如 ASCII、ISO_8859_1,但这些都不起作用。

@body_json['personalizations'][0]['dynamic_template_data'] = {
    'email_title': @email_title,
    'content': @description,
    'subject': "How's it going"
}

SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY']).client.mail._('send').post(request_body: @body_json)
Run Code Online (Sandbox Code Playgroud)

电子邮件主题应正确显示特殊字符,例如 ' & :

gbr*_*non 6

你应该在你的主题部分使用三方括号,即{{{subject}}}带有特殊字符的主题。如果您使用双括号方法,您的字符串将被 HTML 编码。

从 SendGrid 存储库https://github.com/sendgrid/sendgrid-nodejs/issues/741#issuecomment-422026634检查此链接