5

我在 sendgrid api v3 的帮助下发送了一封电子邮件,但收到了警告/错误:

带有字符 '、" 或 & 的内容可能需要用三个括号 {{{ content }}} 进行转义

在我的 api json 中,我添加了一个包含&字符的链接:

{"dynamic_template_data": {"link":"...&..."}}

在我的模板中,我使用了三个括号{{{ link }}}

一切都按预期工作 - 电子邮件包括。链接已发送 - 但我总是收到警告/错误。

我错过了 json 中的某些内容吗?

4

2 回答 2

3

我查看了他们的 node.js 代码,只要任何内容​​字符串有一个 (",',&) 它就会控制台警告您看到的消息。

if (/['"&]/.test(value)) {
   console.warn(DYNAMIC_TEMPLATE_CHAR_WARNING);
}

参见:https ://github.com/sendgrid/sendgrid-nodejs/blob/47b6a5cd583cc10544ac19434419bdda5272b107/packages/helpers/classes/mail.js

您可以注意到在下面 sendgrid 的电子邮件模板中使用 2 对 3 括号的区别: 在此处输入图像描述

于 2019-08-12T00:16:13.113 回答
0

你可以hideWarning: true在你的配置中设置它。

样本

const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const msg = {
  to: 'recipient@example.org',
  from: 'sender@example.org',
  templateId: 'd-f43daeeaef504760851f727007e0b5d0',
  dynamic_template_data: {
    subject: 'Testing Templates',
    name: 'Some One',
    city: 'Denver',
    company: 'Recipient & Sender'
  },
  hideWarnings: true // now the warning won't be logged
};
sgMail.send(msg);
于 2022-01-28T11:32:31.810 回答