This example demonstrates how to setup S22.Imap in order to listen for IMAP IDLE notifications.
Receiving IMAP IDLE notifications
CopyC#
using System;
using S22.Imap;
namespace Test {
class Program {
static void Main(string[] args)
{
using (ImapClient client = new ImapClient("imap.gmail.com", 993, "username",
"password", AuthMethod.Login, true))
{
// We should make sure IDLE is actually supported by the server.
if(client.Supports("IDLE") == false) {
Console.WriteLine("Server does not support IMAP IDLE");
return;
}
// We want to be informed when new messages arrive.
client.NewMessage += new EventHandler<IdleMessageEventArgs>(OnNewMessage);
// Put calling thread to sleep. This is just so the example program does
// not immediately exit.
System.Threading.Thread.Sleep(60000);
}
}
static void OnNewMessage(object sender, IdleMessageEventArgs e)
{
Console.WriteLine('A new message has been received. Message has UID: ' +
e.MessageUID);
// Fetch the new message's headers and print the subject line
MailMessage m = e.client.GetMessage( e.MessageUID, FetchOptions.HeadersOnly );
Console.WriteLine("New message's subject: " + m.Subject);
}
}
}