MailBee.NET Objects 3.1

Smtp.BeginExecuteCustomCommand Method 

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

public IAsyncResult BeginExecuteCustomCommand(
   string commandString,
   AsyncCallback callback,
   object state
);

Parameters

commandString
User-defined command text (including line terminator).
callback
The AsyncCallback delegate. You can leave it a null reference (Nothing in Visual Basic) if you do not use callbacks.
state
An object that contains state information for this request. You can leave it a null reference (Nothing in Visual Basic).

Return Value

An IAsyncResult that references the asynchronous user-defined command execution.

Remarks

This method is an asynchronous version of ExecuteCustomCommand.

Exceptions

Exception Type Condition
MailBeeInvalidStateException There is already an operation in progress.

Example

This WinForms samples verifies e-mail address syntax by sending VRFY command to the SMTP server (the SMTP server must support VRFY command). The sample gets notified of VRFY command completion by using a callback function.

[C#]
// To use the code below, import MailBee namespaces at the top of your code.
using MailBee;
using MailBee.SmtpMail;

// Put the code below inside your class.

// ExecuteCustomCommand callback function.
private void ExecuteCustomCommandCallback(IAsyncResult result)
{
    Smtp mailer = (Smtp)result.AsyncState;

    try
    {
        // If this method does not throw exception, VRFY command 
        // is supported, and the e-mail address validation passed.
        // It's up to the server to decide whether to validate just 
        // syntax or check if such e-mail address really exists.
        mailer.EndExecuteCustomCommand();
        MessageBox.Show("The e-mail address is correct");
    }
    catch (MailBeeSmtpNegativeResponseException e)
    {
        MessageBox.Show(e.ResponseString);
    }

    // Close the connection.
    mailer.Disconnect();
}

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

    mailer.SmtpServers.Add("mail.host.com");

    // Connect to SMTP server and say Hello.
    mailer.Connect();
    mailer.Hello();

    // Initiate an asynchronous e-mail address verification attempt.
    mailer.BeginExecuteCustomCommand("VRFY user@domain.com\r\n",
        new AsyncCallback(ExecuteCustomCommandCallback), mailer);
}
[Visual Basic]
' To use the code below, import MailBee namespaces at the top of your code.
Imports MailBee
Imports MailBee.SmtpMail

' Put the code below inside your class.

' ExecuteCustomCommand callback function.
Private Sub ExecuteCustomCommandCallback(ByVal result As IAsyncResult)
    Dim mailer As Smtp = result.AsyncState

    Try
        ' If this method does not throw exception, VRFY command 
        ' is supported, and the e-mail address validation passed.
        ' It's up to the server to decide whether to validate just 
        ' syntax or check if such e-mail address really exists.
        mailer.EndExecuteCustomCommand()
        MsgBox("The e-mail address is correct")
    Catch e As MailBeeSmtpNegativeResponseException
        MsgBox.Show(e.ResponseString)
    End Try

    ' Close the connection.
    mailer.Disconnect()
End Sub

' The actual code.
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim mailer As New Smtp

    mailer.SmtpServers.Add("mail.host.com")

    ' Connect to SMTP server and say Hello.
    mailer.Connect()
    mailer.Hello()

    ' Initiate an asynchronous e-mail address verification attempt.
    mailer.BeginExecuteCustomCommand("VRFY user@domain.com\r\n", _
        New AsyncCallback(AddressOf ExecuteCustomCommandCallback), mailer)
End Sub

See Also

Smtp Class | MailBee.SmtpMail Namespace | ExecuteCustomCommand