1

I'm Working on a Dummy Project in nextjs and trying to send a reset password message to the user email using mailtrap and nodemailer but i have a problem I can't find any solution for it when I send the request this error happen

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'
}

and Here's my code

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;
pierpy
  • 897
  • 3
  • 14
  • 18

2 Answers2

4

try changing the port, another solution is to try it on another internet network, sometimes in some way, the ip provided by the provider has been blocked, that same error happened to me and my solution was to change the internet network.

  • I was stuck from 2 days in this error and final this answer really helped me. Thank you soo much for your kind sharing. – Riaz Khan Feb 22 '23 at 14:33
1

If you are using school/college wlan/wifi, try using your phone hotspot. Maybe School/College connection is blocking the port.