Link to home
Start Free TrialLog in
Avatar of rubensc
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@anygivendomainname.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
Avatar of JayFromPep
JayFromPep
Flag of United States of America image

There are a ton of answers for this.

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
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)
 

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

Open in new window

Sorry, i put it in c#.

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.
nslookup.exe -type=MX somewhere.com > nslookup.txt

Open in new window

Avatar of rubensc
rubensc

ASKER

DanielBlais: Thanks for the comment, but I don't plan to use a Shell to execute the command.
ASKER CERTIFIED SOLUTION
Avatar of DanielBlais
DanielBlais
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Avatar of rubensc

ASKER

I can do both, no problem
Thanks
So, is there any good solution for you?
Avatar of rubensc

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
I agree the .NET solution is the best one.
Avatar of rubensc

ASKER

I resolve it