MailBee.NET Objects 3.1

Smtp.BeginLogin Method 

Begins an asynchronous request for authenticating the user on the SMTP server.

public IAsyncResult BeginLogin(
   AsyncCallback callback,
   object state
);

Parameters

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 authentication.

Remarks

This method is an asynchronous version of Login.

Exceptions

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

Example

This WinForms sample demonstrates using asynchronous authentication in conjunction with 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.

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

    mailer.EndLogin();
    MessageBox.Show("Authentication succeeded");

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

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

    mailer.SmtpServers.Add("smtp.somehost.com", "jdoe", "secret");

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

    // Initiate an asynchronous authentication attempt.
    mailer.BeginLogin(new AsyncCallback(LoginCallback), 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.

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

    mailer.EndLogin()
    MsgBox("Authentication succeeded")

    ' 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("smtp.somehost.com", "jdoe", "secret")

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

    ' Initiate an asynchronous authentication attempt.
    mailer.BeginLogin(New AsyncCallback(AddressOf LoginCallback), mailer)
End Sub

See Also

Smtp Class | MailBee.SmtpMail Namespace | Login