【问题标题】:UnhandledPromiseRejectionWarning: Error: Forbidden SendGrid WebAPI errorUnhandledPromiseRejectionWarning: 错误: 禁止 SendGrid WebAPI 错误
【发布时间】:2020-05-26 13:05:22
【问题描述】:

//错误//

(node:38736) UnhandledPromiseRejectionWarning: Reference Error: error is not defined

//代码//

const sgMail = require('@sendgrid/mail')

const sendgridAPIKey = 'SG.xxxxx'

sgMail.setApiKey(sendgridAPIKey)

sgMail.send({ 发邮件, 来自:'xxx@gmail.com', 主题:'感谢您的加入', text: '欢迎使用应用程序' })

【问题讨论】:

  • 您能否提供更多有关您要完成的工作以及发生此错误的位置的代码 sn-ps 的信息?

标签: node.js sendgrid webapi


【解决方案1】:

send() 方法返回承诺,你应该await 它。或使用then()

sgMail
    .send({ to: email, from: 'xxx@gmail.com', subject: 'Thanks for joining in', text: 'Welcome to the app' })
    .then(() => { }, error => {
        console.error(error);
    });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-23
    • 2021-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-02
    相关资源
    最近更新 更多