【问题标题】:How to solve code: 'EAUTH', response: '535-5.7.8 Username and Password not accepted.responseCode: 535, command: 'AUTH PLAIN'如何解决代码:'EAUTH',响应:'535-5.7.8 用户名和密码不被接受。响应代码:535,命令:'AUTH PLAIN'
【发布时间】:2022-01-19 01:12:41
【问题描述】:

我的网站上有一个联系我的表单,我正在尝试使用 gmail 服务发送电子邮件,它在我的本地开发环境中运行良好,但我遇到了这个问题:

{code: 'EAUTH', response: '535-5.7.8 用户名和密码不被接受。 Lear...mail/?p=BadCredentials e19sm4851511qty.16 - gsmtp',响应代码:535,命令:'AUTH PLAIN'}

我在 Google 上搜索了很多并查看了文档,但我发现的只是打开了 Google 帐户中的“不太安全的应用程序访问”选项,我做到了,我尝试将其关闭再打开并确保它在我的本地机器上工作,但不幸的是,当我将请求发送到 Vercel 端点中的 API 时,它没有工作。

我的反应代码

const sendContactForm = (e) => {
    e.preventDefault()

    Axios.post(
      `${
        process.env.NODE_ENV === 'development'
          ? process.env.REACT_APP_API_LOCAL_URL
          : process.env.REACT_APP_API_URL
      }/contact`,
      {
        theName,
        email,
        subject,
        msg
      }
    )
      .then(({ data }) => {
        setSendStatus(data.sendStatus)
        setSendStatusMsg(data.sendStatusMsg)
        console.log(data)
      })
      .catch((err) => console.error(err))
  }

而我的 NodeJS 代码是:

const nodemailer = require('nodemailer')
const smtpTransport = require('nodemailer-smtp-transport')

module.exports = (req, res) => {
  const { theName, email, msg, subject } = req.body
  // const { MAILER_EMAIL, MAILER_PASS } = process.env

  let transporter = nodemailer.createTransport(
    smtpTransport({
      service: 'gmail',
      port: 465,
      // secure: true,
      auth: {
        user: process.env.MAILER_EMAIL,
        pass: process.env.MAILER_PASS
      }
    })
  )

  const mailOptions = {
    from: email,
    to: process.env.MAILER_EMAIL,
    subject: subject,

    html: `<p>here is simply HTML code</p>`
  }

  transporter.sendMail(mailOptions, (err, info) => {
    if (err) {
      res.send({
        sendStatusMsg: 'Sorry! something went wrong!',
        errResponse: err,
        sendStatus: 0
      })
    } else {
      res.send({
        sendStatusMsg: 'Thanks for contacting us',
        infoResponse: info.response,
        sendStatus: 1
      })
    }
  })
}

非常感谢。

【问题讨论】:

    标签: node.js reactjs gmail nodemailer


    【解决方案1】:

    我发现this question 有同样的问题。除了启用不太安全的应用程序之外,它还有其他建议,您可以查看它并查看它是否有帮助

     

    另外,有些人建议使用XOAuth2 来代替身份验证

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-08-12
      • 2017-07-22
      • 1970-01-01
      • 1970-01-01
      • 2016-05-22
      • 2021-08-05
      相关资源
      最近更新 更多