Node.js中的密码重置

时间:2016-06-26 05:02:50

标签: javascript node.js mean

我正在使用nodemailer向我发送电子邮件。我已经安装了软件包但是我在运行它时似乎收到了一条错误消息"错误未定义"

/* Render home page. */
router.get('/reset', function (req, res, next) {
    if (!req.user) {
        res.render('reset', {
            title: 'Password Reset',
            displayName: req.user ? req.user.displayName : ''
        });
    }
});
/* Render home page. */
router.post('/reset', function (req, res, next) {
    var transporter = nodemailer.createTransport({
        service: 'Gmail',
        auth: {
            user: 'myemail',
            pass: 'email'
        }


    });
    var mailOption = {
        to: 'myemail.com',
        subject: 'Test',
        text: 'Try email' + req.body.name + 'Email' + req.body.email
    }
    transporter.sendMail(mailOption, function (err, info) {
        if (error) {
            console.log(err);
            res.redirect('/');
        }
        else {
            console.log('Send Message: ' + info.response);
            res.redirect('/');
        }
    });
});

1 个答案:

答案 0 :(得分:0)

当您致电transporter.sendMail时,您会在回调函数中使用err作为参数,但请尝试检查error