如何修复Node.js中processTicksAndRejections邮件发送错误?
Node.js发送密码重置邮件时抛出“发送邮件出错”错误
错误信息
Error: there was an error sending the email, try again later at exports.forgotPassword (C:\Users\Abdurehman\Desktop\node course\node practice\FinalYearProject\controllers\authController.js:167:7) at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
问题详情
我在尝试给用户发送密码重置token时遇到上述错误,已经排查过但没找到解决方案。目前还未实现密码重置功能,希望先解决邮件发送token的问题。
相关代码(authController.js)
exports.forgotPassword = async (req, res, next) => { const user = await User.findOne({ email: req.body.email }); if (!user) { return next(new AppError('no user with this email', 404)); } const resetToken = user.createPasswordResetToken(); await user.save({ validateBeforeSave: false }); const resetURL = `${req.protocol}://${req.get( 'host' )}/api/v1/users/resetPassword/${resetToken}`; const message = `forgot your password ? submit a PATCH request with your new password to : ${resetURL}.\n If you didn't forget your password , please ignore this email`; try { await sendEmail({ email: user.email, subject: 'your password reset token (valid for 10 minutes)', message, }); res.status(200).json({ status: 'success', message: 'Token sent to email', }); } catch (err) { user.passwordResetToken = undefined; user.passwordResetExpires = undefined; await user.save({ validateBeforeSave: false }); return next( new AppError('there was an error sending the email , try again later'), 500 ); } };
恳请各位帮忙解决,谢谢!
内容的提问来源于stack exchange,提问作者Abdu Rëhmãñ
相关产品推荐
相关产品推荐

