MailBee.NET Objects 4.0

Pop3.BeginLogin Method 

Begins an asynchronous request for a logging in an account on a POP3 server.

public IAsyncResult BeginLogin(
   string accountName,
   string password,
   AuthenticationMethods authMethods,
   AuthenticationOptions authOptions,
   SaslMethod authUserDefined,
   AsyncCallback callback,
   object state
);

Parameters

accountName
The user account name on the server.
password
The password of the user account on the server.
authMethods
A set of authentication methods which can be used when logging in a mailbox.
authOptions
Specifies the options which affect login process.
authUserDefined
A reference to the instance of user defined authentication method, or a null reference (Nothing in Visual Basic) if user defined authentication is not used.
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 login process.

Remarks

This method is an asynchronous version of Login.

Exceptions

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

Example

This sample demonstrates asynchronous logging in a mailbox and use of a callback function in a console application.

[C#]
using System;
using MailBee;
using MailBee.Pop3Mail;

class Sample
{
    // A callback function.
    private static void LoginCallback(IAsyncResult result)
    {
        Pop3 pop = (Pop3)result.AsyncState;
        pop.EndLogin();
        Console.WriteLine("Overall size of all messages in the inbox is " +
            pop.InboxSize + " bytes");
    }

    // The actual code.
    static void Main(string[] args)
    {
        Pop3 pop = new Pop3();

        pop.Connect("pop.somehost.com");

        // Initiate an asynchronous login attempt.
        IAsyncResult ar = pop.BeginLogin("jdoe", "secret",
            AuthenticationMethods.Auto, AuthenticationOptions.None,
            null, new AsyncCallback(LoginCallback), pop);

        // Simulate some lengthy work here. At the same time,
        // login is executed on another thread.
        System.Threading.Thread.Sleep(3000);

        // If the login attempt is still in progress, then wait until it's finished.
        while (pop.IsBusy) ar.AsyncWaitHandle.WaitOne();

        // Disconnect from the server.
        pop.Disconnect();
    }
}
[Visual Basic]
Imports System
Imports MailBee
Imports MailBee.Pop3Mail

Class Sample
    ' A callback function.
    Private Shared Sub LoginCallback(ByVal result As IAsyncResult)
        Dim pop As New Pop3
        pop = result.AsyncState
        pop.EndLogin()
        Console.WriteLine("Overall size of all messages in the inbox is " & _
            pop.InboxSize & " bytes")
    End Sub

    ' The actual code.
    Shared Sub Main(ByVal args As String())
        Dim pop As New Pop3
        pop.Connect("pop.somehost.com")

        ' Initiate an asynchronous login attempt.
        Dim ar = pop.BeginLogin("jdoe", "secret", _
            AuthenticationMethods.Auto, AuthenticationOptions.None, _
            Nothing, New AsyncCallback(AddressOf LoginCallback), pop)

        ' Simulate some lengthy work here. At the same time 
        ' login is executed on another thread.
        System.Threading.Thread.Sleep(3000)

        ' If the login attempt is still in progress, then wait until it's finished.
        While pop.IsBusy
            ar.AsyncWaitHandle.WaitOne()
        End While

        ' Disconnect from the server.
        pop.Disconnect()
    End Sub
End Class

See Also

Pop3 Class | MailBee.Pop3Mail Namespace | Login | BeginConnect | SaslMethod