Nodemailer sends email witthout error, but I received nothing

血红的双手。 提交于 2019-12-12 04:43:59

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!