我的帐户
LESS SECURED APPS
不支持。
我一直用这个,但现在不再用了。
const shared = require("./../common/shared");
const config = require("./../config");
const nodemailer = require('nodemailer')
class Sender {
constructor(to, subject, content) {
this.userId = shared.formatUserKeyLiteral(to);
this.subject = subject;
this.to = to;
this.content = content;
}
async SEND(subject) {
let arg = {
user: "[email protected]",
pass: "***",
to: this.to,
subject: this.subject,
html: this.content
}
console.log('EMAIL')
const transporter = nodemailer.createTransport({
service: "gmail",
host: "smtp.gmail.com",
port: 587,
secure: false,
auth: {
user: "[email protected]",
pass: "****",
}
});
transporter.verify(function (error, success) {
if(error) {
console.log("NOT PREPARE EMAIL !!!!" + error);
} else {
console.log('Server validation done and ready for messages.')
}
});
const email = {
from: '[email protected]',
to: '[email protected]',
subject: 'ROCKET',
text: 'Now is the time for all good men to send Email via Node.js!'
};
transporter.sendMail(email, function(error, success){
if (error) {
console.log('>>>>>>>>>>>>>>>>>' + error);
} else {
console.log('Nodemailer Email sent: ' + success.response);
}
});
// return new Promise((resolve, reject) => {
// this.GM = require("gmail-send")(arg);
// this.GM((
// subject
// // files: [filepath],
// ), function(err, res) {
// if (err != null) { reject(err); }
// resolve(res);
// });
// });
}
}
module.exports = (to, subject, content) => { return new Sender(to, subject, content) }
错误:
>>>>>>>>>>>>>>>>>Error: Invalid login: 535-5.7.8 Username and Password not accepted. Learn m
ore at
535 5.7.8 https://support.google.com/mail/?p=BadCredentials z6-20020a170906814600b00992a8a5
4f32sm1399961ejw.139 - gsmtp
NOT PREPARE EMAIL !!!!Error: Invalid login: 535-5.7.8 Username and Password not accepted. Le
arn more at
535 5.7.8 https://support.google.com/mail/?p=BadCredentials b17-20020aa7cd11000000b0052241b
8fd0bsm1441933edw.29 - gsmtp
问题是,从 2022 年 5 月 30 日起,安全性较低的应用程序不再支持 Gmail。现在,Gmail API 使用带有令牌的 OAuth2 身份验证进行身份验证,以帮助确保帐户安全。
更多信息
Google 不再支持使用要求您仅使用用户名和密码登录 Google 帐户的第三方应用或设备。
这里是来自 Google 文档的 OAuth2 身份验证实现的快速入门指南。