问题
function sendMail(uid) {
var emailRef = admin.database().ref("users/"+uid+"/email");
emailRef.once("value", function(snapshot) {
var email = snapshot.val();
if (email !== null && email != undefined && email != "") {
fs.readFile('Key/mail.json', 'utf8', function (err, data) {
if (err) throw err;
objMail = JSON.parse(data);
console.log("MAIL OBJECT:"+ objMail.text);
var transporter = nodemailer.createTransport('smtps://email%40mywebsite.com:'+objMail.text+'@smtp.gmail.com');
var mailOptions = {
from: '"Notification" <notification@mywebsite.com>',
to: email,
subject: 'Notification',
html: "<h1>Test</h1>"
};
// send mail with defined transport object
transporter.sendMail(mailOptions, function(error, info){
if(error){
console.log("NOOOO: "+error);
res.send(false);
}
else {
console.log("YESSS");
res.send(true);
}
});
});
}
else {
res.send(false);
}
});
}
All values are printed out correctly:
1) email is the correct one used by the user.
2) objMail.text is the application specific password to use the email address to send the email. (You would use the Less Secure Apps toggle if you didn't use 2FA).
3) "YESSSS" is printed at the end.
The email nodemailer is supposed to send the message to is one I control to test the package. I got it to work on another project and pretty much reused everything to my knowledge.
Would you know what is causing the email to not be received/sent ?
来源:https://stackoverflow.com/questions/46549581/nodemailer-sends-email-witthout-error-but-i-received-nothing