Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imap disconnected every few hours #54

Open
prashb94 opened this issue Jun 29, 2016 · 13 comments
Open

imap disconnected every few hours #54

prashb94 opened this issue Jun 29, 2016 · 13 comments

Comments

@prashb94
Copy link

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

@dpcolaberry
Copy link

@prashb94 same things. Did you get issue fixed?

@prashb94
Copy link
Author

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//issues/54#issuecomment-233208549, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AKUq3C1j3RdgHnblPCkTF-HI-2LReh6Zks5qWq_NgaJpZM4JBEHR.

@smolleyes
Copy link

+1

3 similar comments
@Maples7
Copy link

Maples7 commented Oct 28, 2016

+1

@waqassiddiqi
Copy link

+1

@lucasfernandes4472
Copy link

+1

@lucasfernandes4472
Copy link

Any news?

@ImTheDeveloper
Copy link

@prashb94 as simple as this?

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

@ImTheDeveloper
Copy link

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.

@amirhouieh
Copy link

amirhouieh commented May 5, 2017

@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
Copy link

amirhouieh commented May 5, 2017

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;
	});

@ImTheDeveloper
Copy link

@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.

@Fabomarche
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants