首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Node.js处理sendgrid API时出现问题

使用Node.js处理sendgrid API时出现问题
EN

Stack Overflow用户
提问于 2020-07-15 04:43:40
回答 1查看 271关注 0票数 0
代码语言:javascript
复制
app.post('/users/update',async(req,res)=>{
    try{
        const user = await User.findOne({email:req.body.email});
        if(!user)
        {
            return res.send({message:"Email ID not registered!"})
        }
        // SG.K_2ita5rRLWvBO6ind1FzQ.uXUAMa1IzOHV155Sak74blUlmawGeUeRXQ20O5tFA
        sgMail.setApiKey('SG.K_2ita5rRLWvBO6ind1FzQ.uXUAMa1IzOHV155Sak74blUlmawGeUeRXQ20O5tFA');
        const msg = {
            to: user.email,
            from: 'kartiken@gmail.com',
            subject: 'Validate Your Account',
            text: 'Hello User, here is your OTP: ',
            html: '<strong>21345</strong>',
            };
        sgMail.send(msg)
        .then(()=>{res.render('forgotPass2',{user})})
        .catch((e)=>{console.log('error',e)})
        console.log('Check mail')

    }catch(e){
        res.status(400).send(e)
    }
})

我真的厌倦了寻找这个问题的解决方案。邮件从不发送,无论我做了什么,我每次都会收到一个错误。错误被promise捕获..我在这里附加了这个错误!

代码语言:javascript
复制
Check mail
error ResponseError: Forbidden
    at C:\Users\Niranjan\Desktop\krb\web d\node\login-system\node_modules\@sendgrid\client\src\classes\client.js:133:29
    at processTicksAndRejections (internal/process/task_queues.js:97:5) {
  code: 403,
  response: {
    headers: {
      server: 'nginx',
      date: 'Tue, 14 Jul 2020 20:28:08 GMT',
      'content-type': 'application/json',
      'content-length': '281',
      connection: 'close',
      'access-control-allow-origin': 'https://sendgrid.api-docs.io',
      'access-control-allow-methods': 'POST',
      'access-control-allow-headers': 'Authorization, Content-Type, On-behalf-of, x-sg-elas-acl',
      'access-control-max-age': '600',
      'x-no-cors-reason': 'https://sendgrid.com/docs/Classroom/Basics/API/cors.html'
    },
    body: { errors: [Array] }
  }
}

请帮帮我,这样我才能走得更远。

EN

回答 1

Stack Overflow用户

发布于 2020-07-15 05:04:16

从文档中的此链接可以看到:

https://github.com/sendgrid/sendgrid-nodejs/tree/master/packages/mail

验证发件人身份

“在”发件人身份验证“选项卡中验证电子邮件地址或域。如果没有此验证,您将在尝试发送邮件时收到403禁止响应。”

在您登录您的帐户后

https://app.sendgrid.com/settings/sender_auth/senders

btw代码看起来很好。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62903711

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档