mkozjak / node-telnet-client

A simple telnet client for Node.js
Other
350 stars 97 forks source link

Getting "Error: Cannot connect at Socket.<anonymous>" #233

Closed jpvalery closed 1 year ago

jpvalery commented 1 year ago

Hi there!

Hope you're alright. It feels this could be similar to #46 but I'm not 100% sure.

I'm trying to run this with NextJS on an API route to run a HELO for an email address.

Here's a snippet of that code:

let params = {
        host: 'mx01.mail.icloud.com',
        port: 25,
        timeout: 50,
        negotiationMandatory: false,
    };

    try {
        await connection.connect(params);
    } catch (err) {
        console.log('Do something for this connection error :', err);
    }

I can't run it locally as my ISP is blocking telnet requests.

Deployed on Vercel and getting this error:

Do something for this connection error : Error: Cannot connect
    at Socket.<anonymous> (/var/task/node_modules/telnet-client/lib/index.js:130:35)
    at Object.onceWrapper (node:events:627:28)
    at Socket.emit (node:events:513:28)
    at Socket._onTimeout (node:net:570:8)
    at listOnTimeout (node:internal/timers:569:17)
    at process.processTimers (node:internal/timers:512:7)

I'm a bit confused as what could be missing (as from reading other issues/readme, setting negotiationMandatory to false should allow the connection to happen)—any insights or direction-pointing will be greatly appreciated 🙏

mkozjak commented 1 year ago

Hi, @jpvalery. Are you able to run some regular linux telnet server on Vercel and check if you can telnet to it with a client so you see it's not a networking issue?

jpvalery commented 1 year ago

Hi @mkozjak! Thank you for the quick reply!

I'm not entirely sure—I'll reach out to their team.

Should I take it that, in itself, my snippet shared above should work as is?

Thanks in advance,

jpvalery commented 1 year ago

Update: after some additional digging, I found out that AWS Lambda blocks port 25 (and so Vercel being on top of AWS, it also blocks it).

I passed that first error using port 587 and increasing the timeout parameter