【问题标题】:Error: Bad username/password nodemailer-sengrid-transport use NodeJs错误:错误的用户名/密码 nodemailer-sendgrid-transport 使用 Node Js
【发布时间】:2020-01-21 16:50:46
【问题描述】:

我尝试构建激活电子邮件,但遇到了问题。

 var email = {
                    from: 'Localhost staff, staff@locahost.com',
                    to: user.email,
                    subject: 'Localhsot activation link',
                    text: 'Hello ' + user.name + ', Thank you for regstring at localhost.com. Please click in the following link to compelet your activation: http://localhost:8000/activate/' + user.tomporarytoken,
                    html: 'Hello<strong>' + user.name + '</strong>,<br><br> Thank you for regstring at localhost.com. Please click in the link below to compelet your activation: <br><br><a href="http://localhost:8000/activate/' + user.tomporarytoken + '" >http://localhost:8000/activate/</a> ' 
                    };

                client.sendMail(email, function(err, info){
                if (err){
                    console.log(err);
                }
                else {
                    console.log('Message sent: ' + info.response);
                }
                });
                res.json({ success: true, message: 'Account registed!, Please check your e-mail for activation link.' });
            }
        });
    }
});

在完成注册时他应该已经到了最后一个案例并给我一个消息集但给我一个错误,会发生什么?

Error: Bad username / password
at Request._callback (C:\Users\Hi.Tech\Documents\Mohammed ELamine\Index\Project Simple (Backend + frontend)\Full-Stack-Mean-Js\node_modules\sendgrid\lib\sendgrid.js:88:25)
at Request.self.callback (C:\Users\Hi.Tech\Documents\Mohammed ELamine\Index\Project Simple (Backend + frontend)\Full-Stack-Mean-Js\node_modules\request\request.js:185:22)
at Request.emit (events.js:189:13)
at Request.<anonymous> (C:\Users\Hi.Tech\Documents\Mohammed ELamine\Index\Project Simple (Backend + frontend)\Full-Stack-Mean-Js\node_modules\request\request.js:1161:10)
at Request.emit (events.js:189:13)
at IncomingMessage.<anonymous> (C:\Users\Hi.Tech\Documents\Mohammed ELamine\Index\Project Simple (Backend + frontend)\Full-Stack-Mean-Js\node_modules\request\request.js:1083:12)
at Object.onceWrapper (events.js:277:13)
at IncomingMessage.emit (events.js:194:15)
at endReadableNT (_stream_readable.js:1125:12)
at process._tickCallback (internal/process/next_tick.js:63:19)

【问题讨论】:

    标签: node.js express sendgrid nodemailer


    【解决方案1】:

    这就是你应该如何实现节点邮件程序。有些字段您应该填写,但您没有填写。尝试这种方式,您可以发送电子邮件。

    const messageStructure = {
             from: 'EMAIL',
             to: targetAddress,
             subject,
             attachments,
             html: emailBody
          };
          const transporter = nodeMailer.createTransport({
             host: 'EMAIL_HOST',
             port: PORT,
             secure: false/true,
             auth: {
                user: 'FROM_EMAIL',
                pass: 'FROM_EMAIL_PASSWORD'
             }
          });
          transporter.sendMail(messageStructure, (err, info) => {
             if (err) {
                reject(err);
                printer.printError(err);
             } else {
                printer.printHighlightedLog(info);
                resolve(false);
             }
          });
    

    【讨论】:

    • 这里的电子邮件主机是什么?是 sendgrid 电子邮件 ID 本身吗?
    猜你喜欢
    • 2016-04-09
    • 2016-06-14
    • 1970-01-01
    • 1970-01-01
    • 2016-11-11
    • 2013-06-03
    • 2021-12-24
    • 2018-12-15
    • 1970-01-01
    相关资源
    最近更新 更多