ImapBeginUploadMessage Method

Note: This API is now obsolete.

Begins an asynchronous request for uploading the message into the specified folder on the server.

Namespace: MailBee.ImapMail
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.5.0 build 687 for .NET 4.5
Syntax
[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
)

Parameters

msg
Type: MailBee.MimeMailMessage
A reference to the MailMessage object representing the message to be uploaded.
folderName
Type: SystemString
The full name of the folder to upload the message to.
flags
Type: SystemString
The string containing the message flags (in IMAP4 format) to be assigned to the message, or a null reference (Nothing in Visual Basic) to set default flags at the discretion of the server.
dateTimeString
Type: SystemString
The string containing datetime (in IMAP4 format) to be assigned to the INTERNALDATE attribute of the message (the date of receiving the message by the server), or a null reference to let the server assign its current datetime value.
batchMode
Type: SystemBoolean
If true and LITERAL+ extension is supported by the server, the message will be uploaded in a single network operation; otherwise, in two operations.
result
Type: MailBee.ImapMailUidPlusResult
A reference to the UidPlusResult object to be filled with the outcome of the upload operation reported by UIDPLUS enabled server (the outcome includes the UID assigned to the uploaded message and the UIDVALIDITY of the folder the message was uploaded to), or a null reference if the application does not need this information.
callback
Type: SystemAsyncCallback
The AsyncCallback delegate. You can leave it a null reference (Nothing in Visual Basic) if you do not use callbacks.
state
Type: SystemObject
An object that contains state information for this request. You can leave it a null reference (Nothing in Visual Basic).

Return Value

Type: IAsyncResult
An IAsyncResult that references the asynchronous upload process.
Exceptions
ExceptionCondition
MailBeeInvalidStateExceptionThere is already an operation in progress.
Remarks
Examples
This sample demonstrates asynchronous uploading a message into "Draft" folder and use of a callback function in a console application.
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();
    }
}
See Also