我只是想为 SendGrid 设置试用电子邮件,这是我第一次使用它,所以我确信这很简单,但我似乎无法替换占位符数据。
我正在使用这样的 NodeJS 库:
sgMail.setApiKey(mailConfig.apiKey);
const msgConfig = {
to: email,
from: mailConfig.defaults.from,
templateId: mailConfig.templates.registrationConfirmation,
substitutions: {
'--displayName--': original.displayName,
'--companyName--': 'Hello world'
}
};
console.log('Sending: ', msgConfig);
// now send the registration confirmation email.
return sgMail.send(msgConfig).then(() => {
console.log('done.');
})
.catch((err) => {
console.error(JSON.stringify(err));
});
在模板中,我使用可视化编辑器添加了一个文本块:
Hello --displayName--
We would love to take this opportunity to welcome you to the store.
from
--companyName--
但是,当我运行测试以发送电子邮件时,它可以发送邮件,但不会替换占位符。
我在这里想念什么?