gpt4 book ai didi

javascript - Node.js nodemailer - 等待新的 promise 解决错误

转载 作者:太空宇宙 更新时间:2023-11-04 03:14:38 24 4
gpt4 key购买 nike

我将node.js与nodemailer一起使用,我得到的是这样的:

let mail = await new Promise((resolve,reject)=>{
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
console.log(error);
reject(error);
} else {
res.status(200).json({ "success": true, "message": 'Thank you for your registration! We\'ve sent you an email to confirm!' });
resolve(mail);
}
});
});

它正在发送邮件,但我收到此错误:

/home/project/controllers/signup.js:139
resolve(mail);
^
ReferenceError: mail is not defined
at transporter.sendMail (/home/project/controllers/signup.js:139:15)
at transporter.send.args (/home/project/node_modules/nodemailer/lib/mailer/index.js:226:21)
at callback (/home/project/node_modules/nodemailer/lib/sendmail-transport/index.js:90:28)
at ChildProcess.sendmail.once.code (/home/project/node_modules/nodemailer/lib/sendmail-transport/index.js:131:28)
at Object.onceWrapper (events.js:286:20)
at ChildProcess.emit (events.js:198:13)
at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12)
[nodemon] app crashed - waiting for file changes before starting...

这个解析(邮件)我的使用方式不合法吗?

最佳答案

let mail = await new Promise((resolve,reject)=>{
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
console.log(error);
reject(error);
} else {
res.status(200).json({ "success": true, "message": 'Thank you for your registration! We\'ve sent you an email to confirm!' });
// change below
resolve(info);
}
});
});

上面的内容应该适合您使用传递给 sendMail 回调的 info 进行解析。

关于javascript - Node.js nodemailer - 等待新的 promise 解决错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58416812/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com