【发布时间】:2021-11-09 23:02:53
【问题描述】:
我成功通过passportjs 进行身份验证,但nodemailer 仅使用console.cloud.google 中使用的一封电子邮件发送电子邮件。
当我尝试其他 gmail 帐户时,我收到此错误:
错误:无效登录:535-5.7.8 不接受用户名和密码。 在 535 5.7.8 了解更多信息 https://support.google.com/mail/?p=BadCredentialsu6sm13346885wrp.0 - gsmtp 在 SMTPConnection._formatError (/var/www/html/Recrute/node_modules/nodemailer/lib/smtp-connection/index.js:784:19) 在 SMTPConnection._actionAUTHComplete (/var/www/html/Recrute/node_modules/nodemailer/lib/smtp-connection/index.js:1536:34) 在 SMTP 连接。 (/var/www/html/Recrute/node_modules/nodemailer/lib/smtp-connection/index.js:1515:26) 在 SMTPConnection._processResponse (/var/www/html/Recrute/node_modules/nodemailer/lib/smtp-connection/index.js:947:20) 在 SMTPConnection._onData (/var/www/html/Recrute/node_modules/nodemailer/lib/smtp-connection/index.js:749:14) 在 TLSSocket.SMTPConnection._onSocketData (/var/www/html/Recrute/node_modules/nodemailer/lib/smtp-connection/index.js:189:44) 在 TLSSocket.emit (events.js:376:20) 在 addChunk (internal/streams/readable.js:309:12) 在 readableAddChunk (internal/streams/readable.js:284:9) 在 TLSSocket.Readable.push (internal/streams/readable.js:223:10) { code: 'EAUTH', response: '535-5.7.8 Username and Password not 公认。了解更多\n' + '535 5.7.8 https://support.google.com/mail/?p=BadCredentials u6sm13346885wrp.0 - gsmtp',响应代码:535,命令:'AUTH XOAUTH2' }
我添加了所有的电子邮件来测试用户。
代码
type: 'oauth2',
user: req.user.email,
clientId: clientId,
clientSecret: clientSecret,
refreshToken: refreshToken,
};
var mailOptions = {
from: req.user.email,
to: 'email@gmail.com',
subject: req.query.sbjct,
text: req.query.msg,
html: req.query.msg,
};
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: auth,
});
transporter.sendMail(mailOptions, (err, res) => {
if (err) {
return console.log(err);
} else {
res.send('done !');
} ```
【问题讨论】:
-
您应该在您的 Gmail Id(hotter.io/docs/email-accounts/secure-app-gmail) 上启用“不太安全”,然后重试
-
问题是我避免这样做,我不想强迫用户这样做
标签: javascript node.js gmail-api nodemailer