nodemailer && mailtrap -> connect ETIMEDOUT error

4k views Asked by At

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;
2

There are 2 answers

1
Luis Miguel AvendaƱo Lozano On BEST ANSWER

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.

0
Sachin Singh On

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