node-imap icon indicating copy to clipboard operation
node-imap copied to clipboard

Cannot get the first example to run?

Open rdgauthier opened this issue 5 years ago • 2 comments

I got this error

Error [ERR_STREAM_DESTROYED]: Cannot call write after a stream was destroyed
    at doWrite (_stream_writable.js:399:19)
    at clearBuffer (_stream_writable.js:542:7)
    at Socket.Writable.uncork (_stream_writable.js:338:7)
    at JSStreamSocket.doWrite (internal/js_stream_socket.js:171:17)
    at JSStream.onwrite (internal/js_stream_socket.js:28:57)
    at Socket.ondata (internal/js_stream_socket.js:72:22)
    at Socket.emit (events.js:315:20)
    at addChunk (_stream_readable.js:295:12)
    at readableAddChunk (_stream_readable.js:271:9)
    at Socket.Readable.push (_stream_readable.js:212:10) {
  code: 'ERR_STREAM_DESTROYED',
  source: 'socket'
}
events.js:292
      throw er; // Unhandled 'error' event
      ^

Error: self signed certificate
    at TLSSocket.onConnectSecure (_tls_wrap.js:1501:34)
    at TLSSocket.emit (events.js:315:20)
    at TLSSocket._finishInit (_tls_wrap.js:936:8)
    at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:710:12)
    at Socket.ondata (internal/js_stream_socket.js:72:22)
    at Socket.emit (events.js:315:20)
    at addChunk (_stream_readable.js:295:12)
    at readableAddChunk (_stream_readable.js:271:9)
    at Socket.Readable.push (_stream_readable.js:212:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:186:23)
Emitted 'error' event on Connection instance at:
    at TLSSocket._onError (C:\Users\TechWreck\node_modules\imap\lib\Connection.js:151:10)
    at TLSSocket.emit (events.js:315:20)
    at emitErrorNT (internal/streams/destroy.js:92:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
    at processTicksAndRejections (internal/process/task_queues.js:84:21) {
  code: 'DEPTH_ZERO_SELF_SIGNED_CERT',
  source: 'socket'
}

rdgauthier avatar Aug 27 '20 20:08 rdgauthier

The server you're connecting to is presenting a self-signed certificate. If this is expected (and not something/someone trying to MITM your connection), then you need to pass the CA or certificate of the server in via the tlsOptions object in order for the connection to be trusted.

mscdex avatar Aug 27 '20 20:08 mscdex

https://github.com/mscdex/node-imap/issues/724 shows the exact change needed in case you use gmail like in the example. (helped me solving the same problem)

BranKohlschreiber avatar Sep 03 '20 07:09 BranKohlschreiber