我有一个嵌套的回调函数,我想从中返回值,但是很遗憾无法执行此操作,有人可以帮助我实现这一目标吗?
export const sendVerificationMail = function(user, token): boolean {
let sent: boolean = false
let transporter = nodemailer.createTransport({
service: 'email',
auth: {
user: 'xyz@email.com',
pass: 'abcdef'
}
})
let link = `http://localhost:8080/user/reset?user=${user.email}&token=${token}`
let mailOptions = {
from: 'xyz@noreply',
to: user.email.toString(),
subject: 'Your Reset Password Link',
html: "<h1>Welcome</h1><br> " +
"Please click the link below to reset your password<br><a href="+link+">Click here to reset</a>"
}
transporter.sendMail(mailOptions, function(error, info) {
if(error) {
console.log(error)
throw error
}
else {
console.log('verification email sent to ' + user.email + ' ' + info)
sent = true
}
})
return sent
}
此sendVerificationMail函数为什么总是返回假值?