public event ExtendedAsyncCompletedEventHandler<TResult> CopyMessageCompleted
Connect to an IMAP server and copy multiple messages from a mailbox to another one asynchronously (Task-based asynchronous approach).
using System; using ComponentPro.Net.Mail; ... // Create a new instance of the Imap class. Imap client = new Imap(); // Connect to the server. client.Connect("myserver"); // Or you can specify the IMAP port with // client.Connect("myserver", 143); // Login to the server. client.Authenticate("user", "password"); // ... // Select 'INBOX' mailbox. client.Select("INBOX"); ImapMessageIdCollection set = new ImapMessageIdCollection(1, 2, 3); // Copy mail messages with sequence numbers 1, 2, and 3 to folder 'my box'. await client.CopyMessageAsync(set, "my box"); // ... Console.WriteLine("Messages copied successfully."); // Disconnect. client.Disconnect();
Connect to an IMAP server and copy multiple messages from a mailbox to another one asynchronously (Event-based asynchronous approach).
using System; using ComponentPro; using ComponentPro.Net.Mail; ... public void DoCopyMessageAsync() { // Create a new instance of the Imap class. Imap client = new Imap(); // Connect to the server. client.Connect("myserver"); // Or you can specify the IMAP port with // client.Connect("myserver", 143); // Login to the server. client.Authenticate("user", "password"); // ... // Register an event handler. client.CopyMessageCompleted += client_CopyMessageCompleted; // Select 'INBOX' mailbox. client.Select("INBOX"); ImapMessageIdCollection set = new ImapMessageIdCollection(1, 2, 3); // Copy mail messages with sequence numbers 1, 2, and 3 to folder 'my box'. client.CopyMessageAsync(set, "my box"); // ... // Disconnect. client.Disconnect(); } void client_CopyMessageCompleted(object sender, ExtendedAsyncCompletedEventArgs<ImapCopyMessageReference> e) { if (e.Error != null) Console.WriteLine("Error: " + e.Error.ToString()); else { Console.WriteLine("Messages copied successfully."); } }