mscdex / node-imap

An IMAP client module for node.js.
MIT License
2.17k stars 380 forks source link

Timed out while connecting to server #807

Open Tiago-Altus opened 4 years ago

Tiago-Altus commented 4 years ago

I am trying to connect to my companies Exchange Server to pull attachments from emails. I am having trouble connecting to the Exchange Server. We use exchange server 2013 sp1.

The setup I have:

var Imap = require('imap'),
    inspect = require('util').inspect;

var imap = new Imap({
  user: 'name@companydomain.com',
  password: 'pass',
  host: 'ews.companydomain.com',
  port: 993,
  tls: true
});

Currently I am just using the sample code from documentation, just to see if I can get connection working. When I run the code I get the following error:

(node:14992) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification.
Error: Timed out while connecting to server
    at Timeout._onTimeout (C:\Users\Tiago\Desktop\BISQL\node_modules\imap\lib\Connection.js:280:15)
    at listOnTimeout (internal/timers.js:549:17)
    at processTimers (internal/timers.js:492:7) {
  source: 'timeout'
}
mscdex commented 4 years ago

The line about NODE_TLS_REJECT_UNAUTHORIZED is concerning, that should never be enabled. You can pass --trace-warnings to node to get a backtrace to locate what is causing that warning.

Are you sure the connection config is correct? Your current configuration is connecting to port 993 with implicit TLS, which is common, but it could be that the server does not have that enabled. It may only be using port 143 and STARTTLS to upgrade the connection via TLS instead.

gsaravanakumar932 commented 2 years ago

Error: Timed out while connecting to server

imap version: imap@0.8.19

@mscdex, I am getting the below issue, It is working fine with LocalHost, but it is not working in server. Could anyone help me on this,

My config as below,

{
  errno: -104,
  code: 'ECONNRESET',
  syscall: 'read',
  source: 'socket',
  level: 'error'
}
{ source: 'timeout', level: 'error' }
{ source: 'timeout', level: 'error' }
{
  message: 'Error: Timed out while connecting to server\n' +
    '    at Timeout._onTimeout (/apps/smartexpense/mailread/node_modules/imap/lib/Connection.js:280:15)\n' +
    '    at listOnTimeout (internal/timers.js:551:17)\n' +
    '    at processTimers (internal/timers.js:494:7)',
  level: 'error'
}

{ message: 'Process will exit with code: 0', level: 'error' }
{ source: 'timeout', level: 'error' }

my config: export const imapConfig = { imap: { user: 'my@email', password: 'password', host: 'outlook.office365.com', port: 993, tls: true, authTimeout: 10000, connTimeout: 30000, keepalive: true, tlsOptions: { rejectUnauthorized: false } };

gsaravanakumar932 commented 2 years ago

imap version: imap@0.8.19

@mscdex, I am getting the below issue, It is working fine with LocalHost, but it is not working in server. My config as below, What should i do, to make it work ?

{
  errno: -104,
  code: 'ECONNRESET',
  syscall: 'read',
  source: 'socket',
  level: 'error'
}
{ source: 'timeout', level: 'error' }
{ source: 'timeout', level: 'error' }
{
  message: 'Error: Timed out while connecting to server\n' +
    '    at Timeout._onTimeout (/apps/smartexpense/mailread/node_modules/imap/lib/Connection.js:280:15)\n' +
    '    at listOnTimeout (internal/timers.js:551:17)\n' +
    '    at processTimers (internal/timers.js:494:7)',
  level: 'error'
}

{ message: 'Process will exit with code: 0', level: 'error' }
{ source: 'timeout', level: 'error' }

my config: export const imapConfig = { imap: { user: 'my@email', password: 'password', host: 'outlook.office365.com', port: 993, tls: true, authTimeout: 10000, connTimeout: 30000, keepalive: true, tlsOptions: { rejectUnauthorized: false } };