// 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:禁止在d:\node-projects\ecom\node_modules@sendgrid\client\src\类\client.js:146:29在processTicksAndRejections(internal/process/task_queues.js:93:5){
代码:403,response:{headers:{server:'nginx',date:'thu,07an 2021年11:55:26 GMT‘,'Content-Type':'application/json','content-lengty':'281',connection:
日志说它失败了,因为它收到了一个禁止的html响应。
请尝试检查您是否在SendGrid设置中设置了发件人身份验证
。
只有设置好了,您才能将电子邮件发送出去。
参考资料:https://sendgrid.com/docs/for-developers/send-email/sender-identity/