New mail received event

0 votes
asked Jan 27, 2016 by lakamraju (200 points)

Are there any events the client can subscribe to, like:

  1. Session expired
  2. New mail received

The aim is to know when a new mail is received. So that there is not need to put our own logic to check for new mails often.

Thank you

Applies to: Rebex Secure Mail

1 Answer

0 votes
answered Jan 27, 2016 by Tomas Knopp (58,890 points)

For a new mail received event, please use the Imap.Notification event in combination with Imap.CheckForUpdates method.

The IMAP protocol features the IDLE command that lets you instruct the server to send you notification about new messages, change of flags, etc.

The event is Imap.Notification and to receive notifications, you have to call the Imap.CheckForUpdates(...) method.

Actually, during the specified time, the server should not close the connection, so to learn that the session has expired, just catch ImapExceptions.

It has already been discussed at our support forum. This post includes a sample code how to implement it or here is another one.

A good ideas is to maintain a list of ID's of messages within your application and refresh the list when you receive the notification from server. That's how most apps do it. Sometimes when multiple clients are connected at the same time the IMAP protocol does not guarantee that all of them will get the notification, so be prepared to watch for changes that you have not been notified too.

...