为什么我在 Node 邮件程序上收到“登录错误”?

编程入门 行业动态 更新时间:2024-10-04 01:18:32

为什么<a href=https://www.elefans.com/category/jswz/34/1771440.html style=我在 Node 邮件程序上收到“登录错误”?"/>

为什么我在 Node 邮件程序上收到“登录错误”?

我尝试使用 Node mailer 发送电子邮件,但一直收到无效登录错误。 我想在用户注册时发送电子邮件。

我启用了双因素验证并为此创建了一个应用程序。我已经获得了这个应用程序的 16 位密码。

这是我得到的错误

535 5.7.8  /?p=BadCredentials i10-20020a05640200ca00b0050bd9d3ddf3sm4737563edu.42 - gsmtp
project/node_modules/nodemailer/lib/smtp-connection/index.js:193:44)
    at TLSSocket.emit (node:events:512:28)
    at addChunk (node:internal/streams/readable:324:12)
    at readableAddChunk (node:internal/streams/readable:297:9)
    at Readable.push (node:internal/streams/readable:234:10) {
  code: 'EAUTH',
  response: '535-5.7.8 Username and Password not accepted. Learn more at\n' +
    '535 5.7.8  /?p=BadCredentials i10-20020a05640200ca00b0050bd9d3ddf3sm4737563edu.42 - gsmtp',
  responseCode: 535,
  command: 'AUTH PLAIN'
}

这是我的代码。

const nodemailer = require("nodemailer");
const sender = process.env.EMAIL_NAME;
const passsword = process.env.EMAIL_PASSWORD;

exports.confrimEmail = (name, recieverEmail) => {
  const transporter = nodemailer.createTransport({
    service: "gmail",
    host: "smtp.gmail",
    auth: {
      user: sender,
      pass: passsword,
    },
  });

  const mailOptions = {
    from: sender,
    to: recieverEmail,
    subject: "Confirm Your Email Address for AASTU-GDSC Inventory API",
    text: `Dear ${name}, \n
           Thank you for signing up for the AASTU-GDSC Inventory API!\n
           We are excited to have you join our community and
           can't wait to see what you will create with our API.
           To complete your registration, we need to confirm your email address.\nPlease click on the link below to verify your email address:\n
           http://localhost:3001/api/users/confrimed
           `,
  };

  transporter.sendMail(mailOptions, (error, info) => {
    if (error) {
      console.log(error);
    } else {
      console.log(mailOptions.from);
      console.log(mailOptions.to);
      console.log(mailOptions.text);
      console.log("Email sent:" + info.response);
    }
  });
};
回答如下:

更多推荐

为什么我在 Node 邮件程序上收到“登录错误”?

本文发布于:2024-05-30 21:03:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1770920.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:我在   错误   邮件   程序   Node

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!