rubensc
asked on
Validate domain name in an emali account
Hi: We want to be able to validate the domain name of an email account when user input this value in our webpage, in short terms we want to accomplish the following scenerio:
user type->: myaccount@anygivendomainna me.com
our routine checks for anygivendomainname.com and check if it really exists, if not then we can inform customer and she/he can double check the field value
Thanks
user type->: myaccount@anygivendomainna
our routine checks for anygivendomainname.com and check if it really exists, if not then we can inform customer and she/he can double check the field value
Thanks
This is an example of splitting the email address apart and checking it with a host lookup:
(The split will put place the username in index 0 and the domain in index 1 of a string array)
(The split will put place the username in index 0 and the domain in index 1 of a string array)
Dim anEmailAddress As String = "somebody@somewhere.com"
Dim mailParts() As String = Split(anEmailAddress, "@")
Dim hostIP As Net.IPHostEntry = Net.Dns.GetHostEntry(mailParts(1))
If Not IsNothing(hostIP) Then
MsgBox("DNS found the domain name: " & hostIP.HostName)
Else
MsgBox("Not a valid domain:" & hostIP.HostName)
End If
Sorry, i put it in c#.
But ladarling is right. Just a simple split and dns check will cover you on it.
But ladarling is right. Just a simple split and dns check will cover you on it.
In VB6 application, I don't know how to do this. You can use the NSLOOKUP command line tool.
Call this line and get back the result in .txt file.
Call this line and get back the result in .txt file.
nslookup.exe -type=MX somewhere.com > nslookup.txt
ASKER
DanielBlais: Thanks for the comment, but I don't plan to use a Shell to execute the command.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Did my previous code not work for you?
I just noticed your question is on both classic VB and VB.NET.
Can you tell us which language you want.
Can you tell us which language you want.
ASKER
I can do both, no problem
Thanks
Thanks
So, is there any good solution for you?
ASKER
I will prefer ASP.NET, the thing with the cmdshell (nslookup) it's external and asyncronous, we are testing the Net.Dns.GetHostEntry stuff, any other idea?
Regards
Regards
I agree the .NET solution is the best one.
ASKER
I resolve it
You can do some pretty cool stuff with System.net.dns that will allow you to check with some dns servers to make sure the domain is a valid domain.
I.E.....
IPHostEntry hostInfo = Dns.GetHostByName("www.contoso.com");
You can also use 3rd party stuff.
here is a link to a topic that touches on just this.
http://www.velocityreviews.com/forums/t81340-dns-lookup-from-net-validate-email-address-domain.html