MailBee.NET Objects 4.0

Smtp.HostResolved Event

Occurs when the SMTP server name is successully resolved into IP address(es).

public event HostResolvedEventHandler HostResolved;

Event Data

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

Property Description
RemoteHost Gets a reference to the resolved host data.
State Gets a reference to the object which was supplied by the developer in state parameter of asynchronous methods of the mailer components.

Remarks

If the SMTP server name was already specified as an IP address, this event is still raised.

When the POP3 server name is resolved into IP address (if POP-before-SMTP authentication is used), this even is raised as well.

Note   No checking if performed on whether the resolved IP address points to the live host.

Example

This sample connects to the SMTP server host and prints all the IP addresses of this host into console. Most hosts, however, have only one IP address assigned.

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

class Sample
{
    // HostResolved event handler.
    private static void OnHostResolved(object sender, HostResolvedEventArgs e)
    {
        foreach (System.Net.IPAddress ip in e.RemoteHost.AddressList)
        {
            Console.WriteLine(ip.ToString());
        }
    }

    // The actual code.
    static void Main(string[] args)
    {
        Smtp mailer = new Smtp();
        mailer.SmtpServers.Add("smtp.domain.com");

        // Subscribe to the HostResolved event.
        mailer.HostResolved += new HostResolvedEventHandler(OnHostResolved);

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

Class Sample
    ' HostResolved event handler.
    Private Shared Sub OnHostResolved(ByVal sender As Object, ByVal e As HostResolvedEventArgs)
        For Each ip As System.Net.IPAddress In e.RemoteHost.AddressList
            Console.WriteLine(ip.ToString())
        Next
    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 HostResolved event.
        AddHandler mailer.HostResolved, AddressOf OnHostResolved

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

See Also

Smtp Class | MailBee.SmtpMail Namespace | SocketConnected | Connected