MailBee.NET Objects 4.0

Smtp.Connected Event

Occurs when the connection with the server is successfully established.

public event ConnectedEventHandler Connected;

Event Data

The event handler receives an argument of type ConnectedEventArgs containing data related to this event. The following ConnectedEventArgs properties provide information specific to this event.

Property Description
Protocol Gets application-level protocol of the established connection.
RemoteEndPoint Gets a reference to the end point of the remote host to which the connection was established.
RemoteHostName Gets the name of the remote host to which the connection was established.
State Gets a reference to the object which was supplied by the developer in state parameter of asynchronous methods of the mailer components.

Remarks

This event indicates successful completion of the connection procedure, while SocketConnected event (occurs before Connected) indicates the connection request from MailBee was accepted by the server, and the SMTP connection procedure will now begin.

If POP-before-SMTP authentication is used and MailBee successfully connects to the POP3 server, this event is raised as well. The developer can examine Protocol property value to determine whether the connection was made to POP3 or SMTP server.

Example

This sample uses Connected event to report the successful connection status into console.

[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.domain.com");

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

        mailer.Connect();
        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.domain.com")

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

        mailer.Connect()
        mailer.Disconnect()
    End Sub
End Class

See Also

Smtp Class | MailBee.SmtpMail Namespace | SocketConnected