0

I am trying to send sample mail from my email to other, it is saying

{"message":"Error","error":{"errno":-4039,"code":"ESOCKET","syscall":"connect","address":"40.99.34.150","port":587,"command":"CONN"}}

The API route handler according to 13.4 is


export async function GET(request: NextRequest) {
    const transporter = nodemailer.createTransport({
        service: "gmail",
        auth: {
            user: "<my-email>",
            pass: "<valid-password-of-the-above-email>",
        },
    });
    const data = {
        from: "<my-email>",
        to: "<other-email>",
        text: "What",
        html: "<html><body>hello</body></html>",
        subject: "hello",
    };
    try {
        await transporter.sendMail(data);
        return NextResponse.json({ message: "OK" }, { status: 200 });
    } catch (error) {
        return NextResponse.json({ message: "Error", error }, { status: 500 });
    }
}

Update: enter image description here

Referred below links but were not of much help!

Feel free to redirect me to any other package which supports typescript and nextjs

krishnaacharyaa
  • 14,953
  • 4
  • 49
  • 88
  • can you try `transporter.sendMail(mailOptions, function(error, response){ if (error) { console.log(error); } });` to see the error in detail – buga Jul 29 '23 at 22:49
  • Hi @buga, I tried console log, but was not of much help, I couldn't see any further things in it – krishnaacharyaa Jul 30 '23 at 03:32
  • perhaps you need to wrap `sendMail` with promise since its uses a callback https://stackoverflow.com/questions/75158156/nodemailer-is-not-working-in-live-but-locally-working-fine/75221037?noredirect=1#comment135341922_75221037 – buga Jul 30 '23 at 12:52

0 Answers0