簡體   English   中英

將動態模板與 sendgrid (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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM