PowerTCP Sockets for .NET

from $349.00
Available Platforms
<

DNS MX Lookup C# Code Example

See all PowerTCP Sockets for .NET Samples and Code Examples

 

The following C# example demonstrates an MX Lookup DNS operation in a Console environment. The application retrieves mail hosts for a specified email address.

 

Dns dns1 = new Dns();
DnsSlave dnsSlave1 = new DnsSlave(dns1, new IPEndPoint(System.Net.IPAddress.Any, 0));
string address = "support@dart.com";

//Add a DNS server for name resolution.
dns1.Servers.Add(new IPEndPoint("8.8.8.8"));

//Lookup mail servers associated with the passed in address.
MxHostEntry[] servers = dnsSlave1.GetMxHostEntries(address, dns1.Servers[0]);

//Build a string from the results and and display it.
string results = "The following mail servers were returned:\r\n";
for (int i = 0; i < servers.Length; i++)
    results += servers[i].HostName + " (" + servers[i].Preference.ToString() + ")\r\n";

Console.WriteLine(results);
Console.WriteLine("Press <enter> to exit.");
Console.ReadLine();

 

To download a trial please visit the PowerTCP Sockets for .NET product page.