MailBee.NET Objects 7.2

Smtp.MessageMXLookupDone Event

Occurs in direct send mode after the component finished DNS MX lookup of SMTP MX servers of recipients domains.

public event SmtpMessageMXLookupDoneEventHandler MessageMXLookupDone;

Event Data

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

Property Description
FailedDomains Gets the list of domains MX lookup failed for.
IntendedDomains Gets the list of domains of the message recipients.
MailMessage Gets the mail message which is being sent.
State Gets a reference to the object which was supplied by the developer in state parameter of asynchronous methods of the mailer components.
SuccessfulDomains Gets the list of domains MX lookup succeeded for.

Remarks

If the message is sent without SMTP relay server directly to MX servers of recipient domains, the component must first discover these servers by performing MX lookup queries to DNS servers. Once this process is finished, the component raises MessageMXLookupDone and starts submitting the mail message to the discovered MX servers.

Example

This sample sends a message in direct send mode to 3 recipients on 2 domains. MessageMXLookupDone event is raised 1 time.

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

class Sample
{
    // MessageMXLookupDone event handler.
    private static void OnMessageMXLookupDone(object sender,
        SmtpMessageMXLookupDoneEventArgs e)
    {
        // Create and display comma-separated list of domains for which 
        // SMTP MX servers have been found.
        string domains = string.Join(", ",
            (string[])ArrayList.Adapter(e.SuccessfulDomains).ToArray(typeof(string)));

        Console.WriteLine("Will send to MX servers of the following domains: " + domains);
    }

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

        // Get DNS servers from config file/OS settings.
        mailer.DnsServers.Autodetect();

        // Subscribe to the MessageMXLookupDone event.
        mailer.MessageMXLookupDone +=
            new SmtpMessageMXLookupDoneEventHandler(OnMessageMXLookupDone);

        // Send a message to 3 recipients on 2 domains.
        mailer.To.AsString = "user1@domain1.com, user2@domain1.com, user2@domain2.com";
        mailer.From.Email = "sender@domain.com";
        mailer.Subject = "Test message";
        mailer.Send();

        Console.WriteLine("Sent to: " + mailer.GetAcceptedRecipients().ToString());
    }
}
[Visual Basic]
Imports System
Imports System.Collections
Imports MailBee
Imports MailBee.SmtpMail

Class Sample
    ' MessageMXLookupDone event handler.
    Private Shared Sub OnMessageMXLookupDone(ByVal sender As Object, _
        ByVal e As SmtpMessageMXLookupDoneEventArgs)
        ' Create and display comma-separated list of domains for which 
        ' SMTP MX servers have been found.
        Dim domains As String
        domains = String.Join(", ", ArrayList.Adapter(e.SuccessfulDomains).ToArray())

        Console.WriteLine("Will send to MX servers of the following domains: " & domains)
    End Sub

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

        ' Get DNS servers from config file/OS settings.
        mailer.DnsServers.Autodetect()

        ' Subscribe to the MessageMXLookupDone event.
        AddHandler mailer.MessageMXLookupDone, AddressOf OnMessageMXLookupDone

        ' Send a message to 3 recipients on 2 domains.
        mailer.To.AsString = "user1@domain1.com, user2@domain1.com, user2@domain2.com"
        mailer.From.Email = "sender@domain.com"
        mailer.Subject = "Test message"
        mailer.Send()

        Console.WriteLine("Sent to: " & mailer.GetAcceptedRecipients().ToString())
    End Sub
End Class

See Also

Smtp Class | MailBee.SmtpMail Namespace