簡體   English   中英

無法使用 sendgrid 發送 email

[英]unable to send email using 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 
    
   

ResponseError: Forbidden at D:\node-projects\ecom\node_modules@sendgrid\client\src\classes\client.js:146:29 at processTicksAndRejections (internal/process/task_queues.js:93:5) {
代碼:403,響應:{ 標頭:{ 服務器:'nginx',日期:'Thu,2021 年 1 月 7 日 11:55:26 GMT','content-type':'application/json','content-length': '281',連接:'close','access-control-allow-origin':'https://sendgrid.api-docs.io','access-control-allow-methods':'POST','access -control-allow-headers':'授權,內容類型,代表,x-sg-elas-acl','access-control-max-age':'600','x-no-cors -原因':'https://sendgrid.com/docs/Classroom/Basics/API/cors.html'},正文:{錯誤:[數組]}}}

日志說它失敗了,因為它收到了 Forbidden html 響應。
嘗試檢查您是否在 SendGrid 設置中設置了Sender Authentication
僅當您完成此設置后,您才能將 email 發送出去。

參考: https://sendgrid.com/docs/for-developers/sending-email/sender-identity/

您需要驗證您的單一發件人 email 才能解決此錯誤

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM