我希望使用SendGrid模板发送电子邮件。我使用标准的 v3 api 和一个简单的 axios 调用。
我希望使用模板发送电子邮件。邮件应包含许多行和列。我不知道创建模板时会有多少行/列。行/列的数量将取决于仅在撰写电子邮件时才知道的数据。
在我的代码中,我希望:
- 使用 HTML 或其他推荐的方法收集数据并组成我希望的尽可能多的行/列。
- 使用模板编写消息,并使用“personalisations/dynamic_template_data”或任何其他推荐的方法将我的 HTML 从 (1) 插入到模板中。
- 发送电子邮件。
- 我希望电子邮件将我的 HTML 行/列视为 HTML。
我的代码(不起作用 - HTML 被视为文本):
//Coompose HTML
let alertHtml = ''
noteObjArray.forEach((nototObj)=>{
...
alertHtml += (myDate !== '') ? `- ${someText} ${myDate } ` : ''
...
alertHtml += '<br/>'
})
//Send mail using SendGrid
const mailSender = firebaseFunctionsConfig.sendgrid.sender
const msg = {
personalizations: [{
to: [{email, name}],
dynamic_template_data: {userName:name, amount, alertHtml}
}],
from: {email: mailSender.email, name: mailSender.name},
reply_to: {email: mailSender.replyemail, name: mailSender.replyname},
template_id: 'a-000078d4b2eb666940bbg1ee66s'
// "content": [{"type": "text/html"}]
}
提前致谢!/K