【问题标题】:node.js sendgrid with multiple recipients get blank value when adding substitution具有多个收件人的node.js sendgrid在添加替换时获得空白值
【发布时间】:2016-07-04 06:29:18
【问题描述】:

我在使用 sendgrid 向多个收件人发送电子邮件时发现了问题。 添加替换时我得到了空白值。

技术

  • node.js
  • sendgrid (v2)

==== 我的示例代码 (node.js) ====

const SENDGRID_API_KEY = 'KEY'
const sendgrid = require('sendgrid')(SENDGRID_API_KEY)

function sendEmailToSupport() {
  const email = new sendgrid.Email({
      from: 'jaewwalletsupport@paysbuy.co.th',
      to: ['user_a@gmail.com', 'user_b@gmail.com', 'user_c@gmail.com']
      html: '<div>test = :test</div>',
      subject: 'dummy'
    })

  email.addSubstitution(':test', 'ddddddddddddd')
  sendgrid.send(email, (err, response) => {
    if (err) {
      console.log(err)
    } else {
      console.log('Yay! Our templated email has been sent')
    }
  })
}

module.exports = {
  sendEmailToSupport
}

====== 结果======

  • user_a@gmail.com 收到内容正确的电子邮件test = ddddddddddddd

  • user_b@gmail.com, user_c@gmail.com 获取邮件为空值test =

看起来email.to 数组中的第一封电子邮件将获得正确的内容,其他电子邮件将获得空白数据。

在sendgrid web admin中,没有错误,一切正常。

如何解决这个问题?

谢谢

【问题讨论】:

    标签: javascript node.js email sendgrid


    【解决方案1】:

    分析 sendgrid 库后,我现在通过编辑这一行找到了解决方案

    email.addSubstitution(':test', new Array(email.to.length).fill('ddddddddddddd'))
    

    【讨论】:

      猜你喜欢
      • 2016-12-08
      • 2017-12-09
      • 1970-01-01
      • 1970-01-01
      • 2017-08-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-21
      相关资源
      最近更新 更多