DnsQueryEx Class

Provides properties and methods for querying MX records of domain from DNS server.


[Visual Basic]
Public Class DnsQueryEx
public class DnsQueryEx
public __gc class DnsQueryEx
public class DnsQueryEx

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Public Methods

S QueryServers Querys MX records of specified domain from DNS server.


DnsQueryEx class is not intended to be used by developer directly, to send email directly without smtp server, please refer to Send E-mail Directly (Simulating SMTP server) section. Anyway, the following example code demonstrates how to use the DnsQueryEx class explicitly.


[C#] To get the full samples of EASendMail, please refer to Samples section.

using System;
using EASendMail;

public void QueryServersAndSendMail()
        SmtpServer[] servers = DnsQueryEx.QueryServers("to@adminsystem.com");

        // query MX record (SMTP server addresses) for to@adminsystem.com
        // try to send email with every SMTP server until the email was sent.
        for (int i = 0; i < servers.Length; i++)
                SmtpServer oServer = servers[i];
                SmtpMail oMail = new SmtpMail("TryIt");
                oMail.From = new MailAddress("from@adminsystem.com");
                oMail.To.Add(new MailAddress("to@adminsystem.com"));

                oMail.Subject = "test subject";
                oMail.TextBody = "test body";

                SmtpClient oSmtp = new SmtpClient();
                oSmtp.SendMail(oServer, oMail);

                // Succeeded, break.
                Console.WriteLine("The email has been sent to {0} successfully!", servers[i]);
            catch (Exception exp)
                Console.WriteLine("Error with server {0} - {1}", servers[i],  exp.Message);
    catch (Exception ep)

Online Examples

Send Email using MX DNS lookup - VB
Send Email using MX DNS lookup - C#
Send Email using MX DNS lookup - C++/CLI