Search code examples
c#gmailpollinggmail-imap

Get new emails as quick as possible


I need to get new emails real as quick as it possible from user's gmail account.

There are 2 options todo that:

1) Poll server periodically (maybe continiously without delay) and check for new messages. (not ideal solution) 2) Use IMAP IDLE. (supported by gmail). This solution looks promising and most eficient. And I tried go that way. Found lib which supported IDLE. It is S22.IMAP mail library. But the problem is that I found some problem with it (or is it IDLE related problem). I don't get OnNewMessage called each time if there are several messages arrived at once. I get 2-3 only when there are 4-6 messages arrived.

Is it IDLE related issue? And do I have to fetch for new messages each time I get EXIST with IDLE? Or is it lib issue?


Solution

  • I used it wrong way. IMAP IDLE is the best way to go. I just forget to stop idling on new message event. It has to be stopped, checked for new messages and then allow app to idle further.