所以我有以下代码:
const nodemailer = require("nodemailer");
const mailer = {
service: "gmail",
auth: {
type: "OAuth2",
user: "mailtester123123123@gmail.com",
clientId: "123123123123123123123123123123.apps.googleusercontent.com",
clientSecret: "krW123123123123123123RqEnS",
refreshToken: "1/SM-7f31231231231231231231231231231231231231231231231UzH",
accessToken: "ya29.1234568791231324564897894231324564697897ss3Ggi-TkWO4HSIZBqHiLpoIkT7H_Sgii4RQxyVJ0QjIfjKB5zk"
}
}
const transporter = nodemailer.createTransport(mailer);
transporter.sendMail({
to: "mailtester123123123@windowslive.com",
subject: "test",
text: "test"
});
但是,当我尝试发送电子邮件时,总是会出现如下错误:错误:无效的登录名:535-5.7.8用户名和密码不被接受。了解更多 535 5.7.8 https://support.google.com/mail/?p=BadCredentials f67-v6sm75536287pfe.75-gsmtp
这是完整的跟踪记录:
(node:25324) UnhandledPromiseRejectionWarning: Error: Invalid login: 535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8 https://support.google.com/mail/?p=BadCredentials f67-v6sm75536287pfe.75 - gsmtp
at SMTPConnection._formatError (D:\Sources\NodeJS\test\node_modules\nodemailer\lib\smtp-connection\index.js:606:19)
at SMTPConnection._actionAUTHComplete (D:\Sources\NodeJS\test\node_modules\nodemailer\lib\smtp-connection\index.js:1335:34)
at SMTPConnection._responseActions.push.str (D:\Sources\NodeJS\test\node_modules\nodemailer\lib\smtp-connection\index.js:1314:26)
at SMTPConnection._processResponse (D:\Sources\NodeJS\test\node_modules\nodemailer\lib\smtp-connection\index.js:762:20)
at SMTPConnection._onData (D:\Sources\NodeJS\test\node_modules\nodemailer\lib\smtp-connection\index.js:558:14)
at TLSSocket._socket.on.chunk (D:\Sources\NodeJS\test\node_modules\nodemailer\lib\smtp-connection\index.js:510:47)
at TLSSocket.emit (events.js:182:13)
at addChunk (_stream_readable.js:283:12)
at readableAddChunk (_stream_readable.js:264:11)
at TLSSocket.Readable.push (_stream_readable.js:219:10)
任何想法都发生了什么以及如何解决?谢谢。
答案 0 :(得分:0)
请进行以下更改。希望对您有所帮助。当您尝试访问google帐户而忘记打开google较少安全性选项时,会发生此错误。
https://myaccount.google.com/lesssecureapps?utm_source=google-account&utm_medium=web
答案 1 :(得分:0)
我不知道您在上面输入的凭据是否是真实的,但是访问令牌,客户端ID等的格式看起来有效。
切勿在互联网上发布您的实际凭证!您基本上只是在互联网上发布了用户名和密码。