[英]How to set links dynamically in Sendgrid v3 using javascript (node.js)
[英]Using dynamic templates with sendgrid (node.js)
我试图通过 SendGrid 直接在 HTML 中发送一个可行的。 但是,它在 email 中返回为简单的 HTML
我的代码:
const message = {
to: email,
from: {
email: "christianguimaraes1996@gmail.com",
},
subject: "Forgot Password",
text: "TOKEN",
token: token,
html: "<p> token: {{{token}}}} </p>",
}
sgMail.send(message)
return res.send()
在 email 中,它是这样收到的:
token: {{{token}}}}
试试这样,
const message = {
to: event.to,
content: {
token: "your token"
},
cc: event.cc,
bcc: event.bcc,
templateId: 'your dynamic tempalte ID from sendgrid"
}
注意:在您的动态模板中,它必须是这样的Ex: Hello {{token}}
content
中的key value
和您的template value expression
应该匹配。
尝试这个
const sgMail = require("@sendgrid/mail"); sgMail.setApiKey( "kjhgdkikgjdguwuywy97397397nvsnbsjgjgs" ); async function sendEmail(data) { const msg = { //extract the email details to: data.receiver, from: data.sender, templateId: "6475hsfhsfhfyrshshfs", //extract the custom fields dynamic_template_data: { firstName: data.name, verificationToken: data.verificationToken, }, }; //send the email try { await sgMail.send(msg); } catch (error) { console.log(error); } }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.