Pop3BeginExecuteCustomCommand Method

Note: This API is now obsolete.

Begins an asynchronous request for sending the specified user-defined command to the server and getting the response.

Namespace: MailBee.Pop3Mail
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 ExecuteCustomCommandAsync instead.")]
public IAsyncResult BeginExecuteCustomCommand(
	string commandString,
	bool multiLineResponse,
	AsyncCallback callback,
	Object state
)

Parameters

commandString
Type: SystemString
User-defined command text (including line terminator).
multiLineResponse
Type: SystemBoolean
true if the given command returns multi-line response on success; false if the given command always produces single-line response.
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 user-defined command execution.
Exceptions
ExceptionCondition
MailBeeInvalidStateExceptionThere is already an operation in progress.
Remarks
This method is an asynchronous version of ExecuteCustomCommand(String, Boolean).
Examples
Sending a mail message to the POP3 server in WinForms application (the POP3 server must support XTND XMIT extension). Sending itself is performed in a few stages:
  1. Send XTND XMIT command
  2. If the server returned positive response indicating XTND XMIT extension is supported, send message source data (encoded as multi-line POP3 request)
  3. If the server returned positive response, the message was accepted for delivery
Callback functions are actively used, and the application message loop never gets blocked (no waiting for an asynchronous method completion is used). Thus, we do need to care about dead-locks which would occur if an event was raised while the message loop was blocked by somewhat like WaitOne(Int32, Boolean) method call. This sample's code does not handle any events, but it's safe to use them if needed.
// To use the code below, import MailBee namespaces at the top of your code.
using MailBee;
using MailBee.Pop3Mail;
using MailBee.Mime;

// Put the code below inside your class.

// XTND XMIT callback function.
private void XtndXmitCallback(IAsyncResult result)
{
    Pop3 pop = (Pop3)result.AsyncState;

    // Process the results of XTND XMIT command.
    try
    {
        pop.EndExecuteCustomCommand();
    }
    catch (MailBeePop3NegativeResponseException)
    {
        MessageBox.Show("XTND XMIT command is not supported. The server responded: " +
            pop.GetServerResponse());
        pop.Disconnect();
        return;
    }

    // Create a mail message to be sent.
    MailMessage msg = new MailMessage();
    msg.From.Email = "jdoe@mydomain.com";
    msg.To.AsString = "kathy@herdomain.com";
    msg.Subject = "Meeting request";
    msg.BodyPlainText = "Hi, Kathy,\r\nCan we meet tomorrow?\r\n\r\nRegards,\r\nJohn";

    // Encode the mail message source as multi-line POP3 request.
    string messageSource = System.Text.Encoding.Default.GetString(msg.GetMessageRawData());
    messageSource = messageSource.Replace("\r\n.", "\r\n..");

    // Send the mail message asynchronously.
    pop.BeginExecuteCustomCommand(messageSource + "\r\n.\r\n",
        false, new AsyncCallback(SubmissionCallback), pop);
}

// Mail message submission callback function.
private void SubmissionCallback(IAsyncResult result)
{
    Pop3 pop = (Pop3)result.AsyncState;

    // Process the results of the mail message submission.
    try
    {
        pop.EndExecuteCustomCommand();
        MessageBox.Show("Message submitted for delivery");
    }
    catch (MailBeePop3NegativeResponseException)
    {
        MessageBox.Show("Message was not submitted. The server responded: " +
            pop.GetServerResponse());
    }

    pop.Disconnect();
}

// The actual code.
private void Form1_Load(object sender, System.EventArgs e)
{
    Pop3 pop = new Pop3();

    pop.Connect("pop.mydomain.com");
    pop.Login("jdoe", "secret");

    // Issue XTND XMIT command asynchronously.
    pop.BeginExecuteCustomCommand("XTND XMIT\r\n", false,
        new AsyncCallback(XtndXmitCallback), pop);
}
See Also