Finding DNS servers

One of the (admittedly) harder ways of knowing your SMTP server is to check the Windows registry for the correct keys. But if you don't know your SMTP host, or it isn't working for you, then you now have an alternative:

DNS entries are stored in the Windows registry. The following code goes to the registry and retrieves a list of named servers for each entry. That server list is then returned to the caller, and each server will be substituted for the SMTP hostname you would normally provide, and the sending of the email is attempted until successful:

public static string[] FindDnsServers()
{
RegistryKey start = Registry.LocalMachine;
string DNSservers = @"SYSTEMCurrentControlSetServicesTcpipParameters";
RegistryKey DNSserverKey = start.OpenSubKey(DNSservers);
if (DNSserverKey == null)
{
return null;
}
string serverlist = (string)DNSserverKey.GetValue("NameServer");
DNSserverKey.Close();
start.Close();
if (string.IsNullOrWhiteSpace(serverlist))
{
return null;
}
string[] servers = serverlist.Split(' ');return servers;
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset