首页 > 解决方案 > NodeJS params.Example 未被@sendgrid/mail 使用

问题描述

Watson Assistant 正确传递了我的 params.finalemail 和 params.gustemail。看起来您的 @sendgrid/mail 不接受这些参数的值。这是为什么?

基本上,Watson 将 $guest 电子邮件作为“收件人”电子邮件地址传递,而 $finalemail 包含电子邮件的主体。

我需要我的函数来发送一封电子邮件,其中包含上述变量中​​包含的信息。

const sgMail = require('@sendgrid/mail');
 /*    Replace YOUR-SENDGRID-API-KEY-GOES-HERE with
        the API Key you get from SendGrid.
  */
  sgMail.setApiKey('apikey')

function sendmail(params) {
params.guestemail
params.finalemail


  let msg = {}
  msg.to = params.guestemail
  msg.from = 'example@outlook.com'
  msg.subject = 'Your Reservation'
  msg.html = params.finalemail

  sgMail.send(msg,(error, json) => {
    if (error) {
      console.log(error)
    }
  })
  return { sent: 1 }
}

标签: node.jssendgridwatson-assistantsendgrid-api-v3

解决方案


Sendgrid 将发送文本字段或 html,而不是两者。要发送您想要的消息,您可以添加“此消息仅是 HTML”。在 html 标记中。


推荐阅读