使用带有Gmail密码的nodemailer

问题描述 投票:0回答:1

大家好,我问我是否可以使用我的 gmail 密码而不是应用程序密码来使用 nodemailer。 因为每当我尝试这样做时,我都会收到此错误:

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

node.js authentication security nodemailer
1个回答
0
投票

2022 年 5 月 30 日后的 Nodemailer 和 Gmail

环境.env

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

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: req.body.to,
  cc: req.body.cc,
  bcc: req.body.bcc,
  subject: req.body.subject,
  text: req.body.text,
};

transporter.sendMail(mailOptions, (error, info) => {
  if (error) {
    console.log(error);
  }
});
© www.soinside.com 2019 - 2024. All rights reserved.