MailBee.NET Objects 7.1

Smtp.BeginConnect Method 

Begins an asynchronous request for a connecting to an SMTP server.

public IAsyncResult BeginConnect(
   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 POP-before-SMTP authentication.

Remarks

This method is an asynchronous version of Connect.

Exceptions

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

Example

This console sample connects to the SMTP server asynchronously and handles Connected event. No callback function is used.

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

class Sample
{
    // "Connected" event handler.
    private static void OnConnected(object sender, ConnectedEventArgs e)
    {
        Console.WriteLine("Successfully connected to the server.");
    }

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

        mailer.SmtpServers.Add("smtp.somehost.com");

        // Subscribe to the Connected event.
        mailer.Connected += new ConnectedEventHandler(OnConnected);

        // Initiate an asynchronous connection.
        mailer.BeginConnect(null, null);

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

        // End the connection request.
        mailer.EndConnect();

        mailer.Disconnect();
    }
}
[Visual Basic]
Imports System
Imports MailBee
Imports MailBee.SmtpMail

Class Sample
    ' "Connected" event handler.
    Private Shared Sub OnConnected(ByVal sender As Object, ByVal e As ConnectedEventArgs)
        Console.WriteLine("Successfully connected to the server.")
    End Sub

    ' The actual code.
    Shared Sub Main(ByVal args As String())
        Dim mailer As New Smtp

        mailer.SmtpServers.Add("smtp.somehost.com")

        ' Subscribe to the Connected event.
        AddHandler mailer.Connected, AddressOf OnConnected

        ' Initiate an asynchronous connection.
        mailer.BeginConnect(Nothing, Nothing)

        ' Simulate some lengthy work here. At the same time,
        ' the connection with the server is established on another thread.
        System.Threading.Thread.Sleep(3000)

        ' End the connection request.
        mailer.EndConnect()

        mailer.Disconnect()
    End Sub
End Class

See Also

Smtp Class | MailBee.SmtpMail Namespace | Connect