我尝试构建激活电子邮件,但是遇到了问题。
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)
答案 0 :(得分:0)
这是实现节点邮件程序的方式。有些字段应该填写,而您没有。尝试这种方式,您可以发送电子邮件。
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);
}
});