nodemailer && mailtrap -> 连接 ETIMEDOUT 错误

问题描述 投票:0回答:2

我正在 nextjs 中进行一个虚拟项目,并尝试使用 mailtrapnodemailer 向用户电子邮件发送重置密码消息,但我有一个问题,我在发送时找不到任何解决方案请求这个错误发生

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

这是我的代码

import nodemailer from "nodemailer";

async function SendEmail(options) {
    const transport = nodemailer.createTransport({
        host: "smtp.mailtrap.io",
        port: 2525,
        auth: {
            user: "xxxxxxxxxxxxxx",
            pass: "xxxxxxxxxxxxxx",
        },
    });

    const message = {
        from: `${process.env.SMTP_FROM_NAME} <${process.env.SMTP_FROM_EMAIL}>`,
        to: options.email,
        subject: options.subject,
        text: options.message,
    };

    await transport.sendMail(message, (error, info) => {
        if (error) {
            console.log(error);
        } else {
            console.log("Email sent: " + info.response);
        }
    });
}

export default SendEmail;
node.js next.js smtp nodemailer mailtrap
2个回答
1
投票

尝试更改端口,另一种解决方案是在另一个互联网网络上尝试,有时以某种方式,提供商提供的 ip 已被阻止,同样的错误发生在我身上,我的解决方案是更改互联网网络。


0
投票

如果您使用的是学校/学院的 wlan/wifi,请尝试使用您的手机热点。也许学校/学院连接阻塞了端口。

© www.soinside.com 2019 - 2024. All rights reserved.