Error: connect ETIMEDOUT xxx.xx.xxx.xxx:587 Nodemailer script stopped working with outlook throws

Error: connect ETIMEDOUT xxx.xx.xxx.xxx:587 Nodemailer script stopped working with outlook throws

几个月前,我创建了这个脚本来帮助我一次发送多封邮件,而不是一封接一封地发送,直到现在它都运行良好。

对于这个脚本,我使用了 dotenv、nodemailer 和 nodemon(仅在开发中,当我完成它时我开始使用 npm 运行 开始 运行 它)

    (function main() {

    const { contacts } = contacts_list;

    try {

        const { MAIL_ACCOUNT, MAIL_PASSWORD } = process.env;

        const transport = nodemailer.createTransport({

            // Uses 'pool' attribute: The same connection is used to send up to 100 mails before being disposed.
            pool: true,
            // Sets the number of max connections per transport. Microsoft accepts up to 1 parallel connection for the same client.
            maxConnections: 1,
            logger: true,
            debug: true,
            service: "hotmail",
            auth: {
                user: MAIL_ACCOUNT,
                pass: MAIL_PASSWORD
            },
            tls: { rejectUnauthorized: false }

        })

        // Change mail parameters such as subject, recipients, content, etc
        const mailParams = {
            from: `test <${MAIL_ACCOUNT}>`,
            to: '',
            attachments: [],
            subject: `test`,
            text: `test`,
            html: `<h1>test</h1>`
        }

        // Mail every contact once at a time with its corresponding attachments
        contacts.forEach(async (contact) => {

            mailParams.to = contact.email;
            mailParams.attachments = [...contact.attachments];

            await transport.sendMail(mailParams);

        })


    } catch (err) {
        
        console.error(err);

    }

})();

我已经扫描了被阻止的端口,在尝试使用它时禁用了防火墙,还禁用了防病毒软件。 None 这些方法奏效了。

它抛出以下错误:

node:internal/process/promises:246
          triggerUncaughtException(err, true /* fromPromise */);
          ^

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

Logger 打印以下行:

[2022-02-03 01:39:22] DEBUG Creating transport: nodemailer (6.7.2; +https://nodemailer.com/; SMTP (pool)/6.7.2[client:6.7.2])
[2022-02-03 01:39:22] DEBUG Sending mail using SMTP (pool)/6.7.2[client:6.7.2]
[2022-02-03 01:39:22] DEBUG Sending mail using SMTP (pool)/6.7.2[client:6.7.2]
[2022-02-03 01:39:22] INFO  [#1] Created new pool resource #1
[2022-02-03 01:39:22] DEBUG [#1] Assigned message <567cc726-524b-0bda-5a52-698109ae7d78@hotmail.com> to #1 (1)
[2022-02-03 01:39:22] DEBUG [nHXJGQWMbA] Resolved smtp.live.com as xxx.xx.xxx.xxx [cache miss]
[2022-02-03 01:39:43] ERROR [nHXJGQWMbA] connect ETIMEDOUT xxx.xx.xxx.xxx:587
[2022-02-03 01:39:43] ERROR [#1] Pool Error for #1: connect ETIMEDOUT xxx.xx.xxx.xxx:587
[2022-02-03 01:39:43] ERROR Send Error: connect ETIMEDOUT xxx.xx.xxx.xxx:587
[2022-02-03 01:39:43] DEBUG [nHXJGQWMbA] Closing connection to the server using "destroy"
[2022-02-03 01:39:43] INFO  [#1] Connection #1 was closed

如果你知道如何解决它,请帮助我,我将不胜感激!

解决方案:

最后,感谢@Marco Strahilov 在其他 post 中的回答,我找到了解决方案。实例化传输时,将服务 属性 设置为 'smtp-mail.outlook.com' 而不是 hotmail。我不确定为什么 'hotmail' 停止工作,也不知道为什么 'stmp-email.outlook.com' 现在可以工作。

转到

设置 => 查看所有 Outlook 设置 => 邮件 => 同步电子邮件

这是您正确设置 IMAP、POP、SMTP 的信息

最后,感谢@Marco Strahilov 在其他 post 中的回答,我找到了解决方案。

实例化传输时,将服务 属性 设置为 'smtp-mail.outlook.com' 而不是 hotmail。我不确定为什么 'hotmail' 停止工作。