繁体   English   中英

SMTP 使用 Nodemailer 发送错误 email

[英]SMTP ERROR using Nodemailer to send email

我正在构建一个 web 应用程序,我想向忘记密码的注册用户发送电子邮件。 但是我在通过节点邮件发送邮件时遇到问题。 我不断收到 421 响应错误,表明服务器正忙于连接太多,我不明白为什么。

下面是我的代码和我不断收到的错误。

require('dotenv').config()
const nodeMailer = require('nodemailer')


const sendMail = async (email, token) => {
    const transporter = nodeMailer.createTransport({
      host: process.env.EMAIL_HOST,
      port: 587,
      auth: {
        user: process.env.EMAIL_USER,
        pass: process.env.EMAIL_PASSWORD,
      },
    });
    console.log("passed transportrt ");
    await transporter.sendMail({
        from: process.env.EMAIL_USER,
        to: email,
        subject: "Password RESET",
        text: `Follow this link to reset your password. It expires in 15minutes. \n\n
         http://localhost:4000/reset/${token}`,
    });
    console.log('out') 
}

module.exports = sendMail

其他部分和工作流程运行良好,直到await transporter.sendMail({...这是我一直在下面遇到的错误

Error: Invalid greeting. response=421 Service not available: 421 Service not available
    at SMTPConnection._actionGreeting (.../node_modules/nodemailer/lib/smtp-connection/index.js:1205:27)
    at SMTPConnection._processResponse (.../node_modules/nodemailer/lib/smtp-connection/index.js:947:20)
    at SMTPConnection._onData (.../node_modules/nodemailer/lib/smtp-connection/index.js:749:14)
    at Socket.SMTPConnection._onSocketData (.../node_modules/nodemailer/lib/smtp-connection/index.js:189:44)
    at Socket.emit (node:events:526:28)
    at addChunk (node:internal/streams/readable:315:12)
    at readableAddChunk (node:internal/streams/readable:289:9)
    at Socket.Readable.push (node:internal/streams/readable:228:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
  code: 'EPROTOCOL',
  response: '421 Service not available',
  responseCode: 421,
  command: 'CONN'
}

我可能做错了什么吗? 另外我在 unbuntu 上运行这个(如果它与错误有任何联系)

带有 EPROTOCOL 错误的 421 错误通常意味着邮件客户端无法连接到邮件服务器。 检查两种简单的可能性:

  • process.env.EMAIL_HOST未定义(未在.env文件或操作系统中设置)
  • 您的服务器无法通过端口 587 连接到邮件主机(使用 te.net 很容易检查)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM