Click here to Skip to main content
15,072,311 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How can we prevent invalid domain from being entered into the email address field?
What makes you think that this domain is invalid? It could be a valid domain used for mail, for example...
Mannava Siva Aditya 8-Oct-12 3:37am
If not this try to enter an invalid mail address with invalid domain.
Do you mean "invalid" as not represented by DNS. Is so, try to resolve IP by domain name using DNS. After all, when you obtain it, ping it. I think this is the most guarantee you can possibly have.

You cannot prevent tha. You can check the text entered by e.g. trying to resolve an IP address for that. But it still be actually invalid: many domains were registered just to take money from those who want to use it - you can see that when you enter an address in the browser and a typo happens.
Please see my comment to the question. First, you need to try to resolve IPs via DNS using the domain name using the class System.Net.Dns:[^].

You can also ping the IPs using the class System.Net.NetworkInformation.Ping:[^].

You can find some code sample here:[^].

The successful ping does not proof the domain is valid as a mail delivery agent; and the failed ping does not proof the e-mail is not served at this domain, as the domain could be out of service for a short period of time. It just give you an extra criterion for validity, which is itself does not have strictly 100% validity, which is probably impossible with the present day mail delivery system we all use.


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900