Error: connect ECONNREFUSED Nodemailer Ethereal

Error: connect ECONNREFUSED Nodemailer Ethereal

我在尝试使用来自 nodemailer 的示例时遇到错误。

我对它进行了一些修改,但它具有相同的内核。当我尝试 运行 时,出现此错误:

Error: connect ECONNREFUSED 13.49.22.0:587
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1161:16) {
  errno: -111,
  code: 'ESOCKET',
  syscall: 'connect',
  address: '13.49.22.0',
  port: 587,
  command: 'CONN'
}

我已经搜索过,但找不到关于此的任何答案。我听说将 nodemailer 的版本降级到 4.7.0 可以修复它,但我还没有测试过。

我也测试了与 google 的连接,但没有成功。

其实运行的函数是这样的:

async function nodeMailerMain() {
  // Generate test SMTP service account from ethereal.email
  // Only needed if you don't have a real mail account for testing
  let testAccount = await nodemailer.createTestAccount().catch((err) => console.log(err))

  // create reusable transporter object using the default SMTP transport
  let transporter = await nodemailer.createTransport({
    host: testAccount.smtp.host,
    port: testAccount.smtp.port,
    secure: testAccount.smtp.secure, // true for 465, false for other ports
    auth: {
      user: testAccount.user, // generated ethereal user
      pass: testAccount.pass, // generated ethereal password
    },
  })//.catch((err) => console.log(err))

  console.log(testAccount.smtp.host);

  console.log("successfully created transporter");

  let message = {
    from: 'Sender Name <sender@example.com>',
    to: 'Recipient <recipient@example.com>',
    subject: 'Nodemailer is unicode friendly ✔',
    text: 'Hello to myself!',
    html: '<p><b>Hello</b> to myself!</p>'
  };

  // send mail with defined transport object
  transporter.sendMail(message, (error, info) => {
    if (error) {
      return console.log(error);
    }
    console.log('Email sent: ' + info.response);
    console.log("Message sent: %s", info.messageId);
    // Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321@example.com>
  
    // Preview only available when sending through an Ethereal account
    console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
    // Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...
  });
}

事实证明,由于我使用的是 Gitpod 工作区,因此电子邮件功能已被阻止以避免 spam-bots。有关详细信息,请参阅 Github 上的此问题:https://github.com/gitpod-io/gitpod/issues/8976