微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法使用 sendgrid 发送电子邮件

如何解决无法使用 sendgrid 发送电子邮件

   // this is my code
//unable to send email using sendgrid
// finding email from body
    exports.signUp=async (req,res)=>{
        const userExists = await User.findOne({ email: req.body.email })
        if(userExists){
            return res.status(400).json({
                error:"eamil is already taken"
            })
        }
        const token = jwt.sign(req.body,process.env.ACCOUNT_ACTIVATION,{expiresIn:'20m'})
        const emailSend = {
            from: process.env.EMAIL_FROM,to: req.body.email,subject:`Acoount activation link`,html:`
                <p> Please click the following link to activate</p>
    
                <a>http://localhost:8000/api/auth/activate/${token}</a>
            `
        }
        sgMail.send(emailSend).then(sent=>{
            return res.status(200).json({
                message:'email has been sent to you emailid'
            })
        })
        .catch(err=>console.log(err))
    }
    
    
    
   // this is error am getting
// am getting this error 
    
   

响应错误禁止 在 D:\node-projects\ecom\node_modules@sendgrid\client\src\classes\client.js:146:29 在 processticksAndRejections (internal/process/task_queues.js:93:5) {
代码:403, 回复: { 标题:{ 服务器:'Nginx', 日期:'星期四,2021 年 1 月 7 日 11:55:26 GMT', '内容类型':'应用程序/json', '内容长度':'281', 连接:'关闭', 'access-control-allow-origin': 'https://sendgrid.api-docs.io','访问控制允许方法':'POST', 'access-control-allow-headers':'授权,内容类型,代表,x-sg-elas-acl', “访问控制最大年龄”:“600”, 'x-no-cors-reason': 'https://sendgrid.com/docs/Classroom/Basics/API/cors.html' },正文:{错误:[数组]} } }

解决方法

日志说它失败了,因为它收到了一个 Forbidden html 响应。
尝试检查您是否在 SendGrid 设置中设置了 Sender Authentication
只有在您完成此设置后,您才能将电子邮件发送出去。

参考文献:https://sendgrid.com/docs/for-developers/sending-email/sender-identity/

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。