Begins an asynchronous request for uploading the message into the specified folder on the server.
An IAsyncResult that references the asynchronous upload process.
This method is an asynchronous version of UploadMessage.
| Exception Type | Condition |
|---|---|
| MailBeeInvalidStateException | There is already an operation in progress. |
This sample demonstrates asynchronous uploading a message into "Draft" folder and use of a callback function in a console application.
[C#] using System; using MailBee; using MailBee.ImapMail; using MailBee.Mime; class Sample { // A callback function. private static void UploadMessageCallback(IAsyncResult result) { Imap imp = (Imap)result.AsyncState; try { imp.EndUploadMessage(); Console.WriteLine("The message was successfully uploaded"); } catch (MailBeeException e) { // In callback functions (generally speaking, in worker threads), // it's better to handle exceptions. If exception is not handled, // the worker thread silently dies and the application may never // know that something went wrong. Console.WriteLine(e.Message); } } // The actual code. static void Main(string[] args) { Imap imp = new Imap(); // Connect to the server and log in the account. imp.Connect("imap.somedomain.com"); imp.Login("jdoe", "secret"); // Create a new message. Assume we need to save a draft of the message. MailMessage msg = new MailMessage(); // Initiate an asynchronous upload attempt with the following settings: // - Object to download: msg // - Folder to download to: Draft // - Flags: \Draft // - Message date on server: datetime/timezone of the local computer // - batch mode: enabled // - obtain UID of uploaded message: no, thanks IAsyncResult ar = imp.BeginUploadMessage(msg, "Draft", @"\Draft", null, true, null, new AsyncCallback(UploadMessageCallback), imp); // Simulate some lengthy work here. At the same time, // uploading occurs on another thread. System.Threading.Thread.Sleep(3000); // If the upload process is still in progress, // then wait until it's finished. while (imp.IsBusy) ar.AsyncWaitHandle.WaitOne(); // Disconnect from the server. imp.Disconnect(); } }
[Visual Basic] Imports System Imports MailBee Imports MailBee.ImapMail Imports MailBee.Mime Module Sample ' A callback function. Private Sub UploadMessageCallback(ByVal result As IAsyncResult) Dim imp As Imap = CType(result.AsyncState, Imap) Try imp.EndUploadMessage() Console.WriteLine("The message was successfully uploaded") Catch e As MailBeeException ' In callback functions (generally speaking, in worker threads), ' it's better to handle exceptions. If exception is not handled, ' the worker thread silently dies and the application may never ' know that something went wrong. Console.WriteLine(e.Message) End Try End Sub ' The actual code. Sub Main() Dim imp As New Imap ' Connect to the server and log in the account. imp.Connect("imap.somedomain.com") imp.Login("jdoe", "secret") ' Create a new message. Assume we need to save a draft of the message. Dim msg As New MailMessage ' Initiate an asynchronous upload attempt with the following settings: ' - Object to download: msg ' - Folder to download to: Draft ' - Flags: \Draft ' - Message date on server: datetime/timezone of the local computer ' - batch mode: enabled ' - obtain UID of uploaded message: no, thanks Dim ar As IAsyncResult = imp.BeginUploadMessage(msg, "Draft", "\Draft", _ Nothing, True, Nothing, New AsyncCallback(AddressOf UploadMessageCallback), imp) ' Simulate some lengthy work here. At the same time, ' uploading occurs on another thread. System.Threading.Thread.Sleep(3000) ' If the upload process is still in progress, ' then wait until it's finished. While imp.IsBusy ar.AsyncWaitHandle.WaitOne() End While ' Disconnect from the server. imp.Disconnect() End Sub End Module
Imap Class | MailBee.ImapMail Namespace | UploadMessage