Reputation: 1044
In my application I validate a email domain like this:
public bool DomainValid(string domainName)
{
try
{
IPHostEntry entry = Dns.GetHostEntry(domainName);
return true;
}
catch (Exception)
{
return false;
}
}
The method is good, but not on every cases, like 'mpg.ro' is a valid email domain but it catches an Exception.
Can someone give me another idea of email domain validation in C#?
Upvotes: 1
Views: 1996
Reputation: 1024
From command prompt:
nslookup -type=mx <domain.name>
you can implement this inside C# too and read the answer.
Upvotes: 1
Reputation: 1332
You could do a dns lookup on the mx record. Here's an example at Code Project:
http://www.codeproject.com/KB/IP/dnslookupdotnet.aspx
I hope it will helps you ...
Upvotes: 2
Reputation: 2267
You could request the root of the domain, then parse the HTTP response? If it's 200, you're good to go
Upvotes: 2