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.