mail-listener2 icon indicating copy to clipboard operation
mail-listener2 copied to clipboard

imap disconnected every few hours

Open prashb94 opened this issue 8 years ago • 13 comments

Is there a way to prolong the life of the mail listener connection without having to refresh the code every few hours? I notice that the mail listener disconnects after a while of no traffic.

Thanks

prashb94 avatar Jun 29 '16 12:06 prashb94

@prashb94 same things. Did you get issue fixed?

dpcolaberry avatar Jul 17 '16 22:07 dpcolaberry

Hey,

I just start the connection again if the server disconnects. A temporary fix for now.

On Jul 18, 2016 06:42, dpcolaberry [email protected] wrote:

@prashb94https://github.com/prashb94 same things. Did you get issue fixed?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/chirag04/mail-listener2/issues/54#issuecomment-233208549, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AKUq3C1j3RdgHnblPCkTF-HI-2LReh6Zks5qWq_NgaJpZM4JBEHR.

prashb94 avatar Jul 18 '16 10:07 prashb94

+1

smolleyes avatar Sep 26 '16 13:09 smolleyes

+1

Maples7 avatar Oct 28 '16 09:10 Maples7

+1

waqassiddiqi avatar Jan 15 '17 07:01 waqassiddiqi

+1

lucasfernandes4472 avatar Jan 24 '17 19:01 lucasfernandes4472

Any news?

lucasfernandes4472 avatar Jan 24 '17 19:01 lucasfernandes4472

@prashb94 as simple as this?

mailListener.on('server:disconnected', () => { console.log('imapDisconnected'); mailListener.stop(); mailListener.start(); });

ImTheDeveloper avatar Apr 14 '17 16:04 ImTheDeveloper

I've also noticed that sometimes due to the Idle event firing it can miss emails that have not previously been read. Weirdly if you restart the client it STILL ignores those received emails. You have to mark them as seen and then back to unread for them to parse.

ImTheDeveloper avatar Apr 18 '17 08:04 ImTheDeveloper

@Hardware-Hacks your solution did not work for me! I've tried two ways: 1

        function startListener() {
		if (mailListener) {
			mailListener.stop();
		}
		mailListener = new MailListener(mailListenerOpts);
		mailListener.start();
	}

	startListener();

	mailListener.on('server:connected', () => {
		console.info('IMAP connected');
	});

	mailListener.on('server:disconnected', () => {
		startListener();
	});

	mailListener.on('error', errorHandler);
	mailListener.on('mail', mailHandler);
```

2
```
        mailListener = new MailListener(mailListenerOpts)
	mailListener.start();

	function restartListener() {
		mailListener.stop();
		mailListener.start();
	}

	mailListener.on('server:connected', () => {
		console.info('IMAP connected');
	});

	mailListener.on('server:disconnected', () => {
		restartListener();
	});

	mailListener.on('error', errorHandler);
	mailListener.on('mail', mailHandler);
```

amirhouieh avatar May 05 '17 08:05 amirhouieh

What I do now (although does not sound good) I use forever CLI to ensure that app always run, and then:

	mailListener.on('server:disconnected', () => {
		console.warn('IMAP disconnected');
		throw new Error('Restart app due to IMAP disconnection');
            
                // or process.exit(1); 
               // or process. exitCode =1;
	});

amirhouieh avatar May 05 '17 08:05 amirhouieh

@amirhouieh fully agree there is something fundamentally wrong here and I can't fathom it. I even produced mail-listener-fixed which incorporated the best bits from all the forks in this area. I think there are at least 2 things going wrong, 1 of which is even hitting a timeout, if you use oauth you won't hit the same issue. 2 the IDLE command doesnt seem to receive responses after a while, or it is breaking down on the client side causing the server to disconnect the connection.

I've actually ditched all of this now. For GMail specifically I switched over to context.io and use their npm library to retrieve emails via live sync. It works really good and offers the same functionality.

ImTheDeveloper avatar May 05 '17 08:05 ImTheDeveloper

add on node-modules/mail-listener2/index.js this: MailListener.prototype.start = function() { this.imap.on('ready', imapReady.bind(this)); this.imap.on('close', imapClose.bind(this)); this.imap.connect(); }; MailListener.prototype.restart = function() { console.log('detaching existing listener'); this.imap.removeAllListeners('mail'); this.imap.removeAllListeners('update');

console.log('calling imap connect'); this.imap.connect(); };

and then use it

Fabomarche avatar Aug 29 '22 22:08 Fabomarche