ImapBeginUploadMessage Method |
Note: This API is now obsolete.
Namespace: MailBee.ImapMail
[ObsoleteAttribute("This method is obsolete in .NET 4.5+. Use UploadMessageAsync instead.")] public IAsyncResult BeginUploadMessage( MailMessage msg, string folderName, string flags, string dateTimeString, bool batchMode, UidPlusResult result, AsyncCallback callback, Object state )
Exception | Condition |
---|---|
MailBeeInvalidStateException | There is already an operation in progress. |
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(); } }