【问题标题】:Dynamic data is not sending to sendgrid template动态数据未发送到 sendgrid 模板
【发布时间】:2019-06-16 01:08:12
【问题描述】:

我有 sendgrid 电子邮件模板,我想从我的 nodejs 应用程序发送动态数据,但它显示错误。

这就是我发送数据的方式:

const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY); 

const msg = {
    to: 'me.example18@gmail.com',
    from: 'exmple1@gmail.com',
    templateId:'d-8e322d7da4f44ca1afc76aefb3723444',
    personalizations: [
        {
            dynamic_template_data: {
                Sender_Name: 'Bookbudi',
                Sender_Address: '971/32 alwar gate',
                Sender_City: 'Ajmer',
                Sender_State:'Rajasthan',
                Sender_Zip:'305001'
            }  
        }
    ]   
};

sgMail.send(msg);

请有人告诉我我做错了什么以及我应该如何纠正它。任何帮助将不胜感激。

谢谢

【问题讨论】:

  • 您收到什么错误?
  • code:400,message:'bad request'

标签: node.js sendgrid


【解决方案1】:

我认为您的代码不正确。看这个例子:

 const result = await this.sgMail.send({
            personalizations: [{
                to: this._to,
                dynamic_template_data: Object.assign({}, this._dynamic_template_data, {app: app}, {from: this._from})
            }],
            from: this._from,
            templateId: this._templateId,
        });

尝试将“to”移至个性化数组。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-09
    • 1970-01-01
    • 1970-01-01
    • 2020-11-11
    • 2020-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多