public event EventHandler<TEventArgs> Update
Show how to handle the Update event.
using System; using ComponentPro.Net.Mail; ... public void HandleUpdateEvent() { // Create a new instance. Imap client = new Imap(); client.Update += client_Update; // Connect to the IMAP server. client.Connect("server"); // Authenticate. client.Authenticate("test", "test"); // ... while (!quit) { // Check for updates every 1 min. client.CheckForUpdates(); System.Threading.Thread.Sleep(60 * 1000); // Sleep 1 min. // ... } // ... // Disconnect. client.Disconnect(); } void client_Update(object sender, ImapUpdateEventArgs e) { Console.WriteLine("New event: " + e.Event); }
Shows how to handle Update event and use the Noop method to check for updates from the IMAP server.
using System; using ComponentPro.Net; using ComponentPro.Net.Mail; ... static void Main() { // IMAP server information. const string serverName = "imap.gmail.com"; const string user = "username@gmail.com"; const string password = "password"; const int port = 993; const SslSecurityMode securityMode = SslSecurityMode.Implicit; // Create a new instance of the Imap class. Imap client = new Imap(); // Connect to the server. client.Connect(serverName, port, securityMode); // Login to the server. client.Authenticate(user, password); // Select 'INBOX' mailbox client.Select("INBOX"); client.Update += client_Update; // ... while (!quit) { // ... // Wait for 10 seconds. client.CheckForUpdates(10000); // ... } // ... // Close the connection. client.Disconnect(); } static void client_Update(object sender, ImapUpdateEventArgs e) { switch (e.Event) { case ImapUpdateEvent.MessageCount: Console.WriteLine("New message received."); // You can download the newly received message here. break; case ImapUpdateEvent.MessageRemoved: Console.WriteLine("One or more messages removed."); break; } }