使用nodemailer和Gmail密码

cotxawn7  于 11个月前  发布在  Node.js
关注(0)|答案(1)|浏览(110)

嗨,伙计们,我问我是否可以使用nodemailer与我的gmail密码,而不是应用程序密码。因为每当我尝试这样做,我得到这个错误:

Error in sending email: Error: Invalid login: 534-5.7.9 Application-specific password required. Learn more at

字符串
534 5.7.9 https://support.google.com/mail/?p=InvalidSecondFactor h5-20020a170906718500b009ddf38056f8sm8150481ejk.118 - gsmtp

u4vypkhs

u4vypkhs1#

  • 谷歌

Sign in with app passwords

  • 节点邮件程序

Using Gmail

  • stackoverflow

2022年5月30日之后的Nodemailer和Gmail

index.js

const transporter = nodemailer.createTransport({
  service: process.env.MAIL_SERVICE,
  auth: {
    user: process.env.MAIL_USERNAME,
    pass: process.env.MAIL_PASSWORD,
  },
});

const mailOptions = {
  from: process.env.MAIL_USERNAME,
  to: process.env.MAIL_USERNAME,
  subject: req.body.subject,
  text: req.body.text,
};

transporter.sendMail(mailOptions, (error, info) => {
  if (error) {
    console.log(error);
  } else {
    console.log(info);
  }
});

字符串

环境.env

MAIL_SERVICE='gmail'
MAIL_USERNAME='s[email protected]'
MAIL_PASSWORD='[email protected]'

相关问题