首页 > 解决方案 > Nodemailer 发送包含 MySQL 数据库信息的电子邮件

问题描述

我正在尝试使用 Nodemailer 进行密码恢复。基本上,用户将在 HTML 表单中输入电子邮件地址,然后使用 Nodemailer 发送电子邮件。该电子邮件将包含来自 MySQL 数据库的密码。我的问题是,密码显示为“未定义”。

app.post('/Forgot_Password_V1', function(request, response) {
    var connection = request.app.get('pool'); 
    connection.query('SELECT password FROM accounts WHERE email = ?', [request.body.email], function(error, results, fields) {  
https://myaccount.google.com/lesssecureapps?pli=1
    { account: results[0] };

        var transporter = nodemailer.createTransport({
            service: 'Gmail',
            auth: {
                user: 'user',
                pass: 'password'
            }
        });

            //send to the email entered in the form input
            var mailOptions = {     
                from: 'email',
                to: request.body.email,
                subject: 'Password Request',
                text: 'You have requested to recover the password of your account.\n\n' +

                request.password + // I tried this
                account.password + // I also tried this
                '\n End.\n'
            };

电子邮件中密码的输出显示“未定义”。我一直在尝试不同的事情无济于事。有人可以帮助我做错什么吗?

标签: mysqlnodemailer

解决方案


推荐阅读