joe_g99
asked on
Email address validation
Hi, im trying to create some code to verify that a e-mail address actually exists (not just checking the syntax is corect) without actually sending an email to the address.
I know this is possible using com objects and DNS lookup as I have seen websites offering to sell these objects adn demonstrating them ie:
http://www.hexillion.com/samples/ValidateEmail.asp
but I'd rather do this myself so If anybody knows how, or a url for free source code for creating the com object that would be greatly appreciated
I know this is possible using com objects and DNS lookup as I have seen websites offering to sell these objects adn demonstrating them ie:
http://www.hexillion.com/samples/ValidateEmail.asp
but I'd rather do this myself so If anybody knows how, or a url for free source code for creating the com object that would be greatly appreciated
also check here:
http://www.hexillion.com/software/components/HexValidEmail/
http://www.nehuenmultimedia.com.ar/html/vmailcom.html
http://www.email-screen.com/index-emailscreen.html
jmail has an internal MXlookup.. you might need to check it:
http://www.dimac.net/
http://www.hexillion.com/software/components/HexValidEmail/
http://www.nehuenmultimedia.com.ar/html/vmailcom.html
http://www.email-screen.com/index-emailscreen.html
jmail has an internal MXlookup.. you might need to check it:
http://www.dimac.net/
I don't think you're solving your problem by doing this route. I can put in an email address of foo@aol.com and it will return back okay.
What you could do is disable the account and send a password verification to that email address, so they have to either click on a link or have to log in with a random password.
Other than that, as Silvers5 pointed out, I've had good success with aspExec from www.serverobjects.com
What you could do is disable the account and send a password verification to that email address, so they have to either click on a link or have to log in with a random password.
Other than that, as Silvers5 pointed out, I've had good success with aspExec from www.serverobjects.com
network tools validates the mailbox.. and i guess other components might try to connect to the mail server and validate the box.. check it..
An interaction as thunderchicken pointed is a good solution too but will require extra development from your side and interaction from the client..
here is the code of such a thing using aspemail component..
here's a code I wrote a while ago.. it uses components I wrote to fetch a send data to the database and the aspemail component..
<%
option explicit
Response.Buffer=true
Dim ErrStr, GetDataObj, EmailX, NameX, IsRsFetchedCats, NewsAlso, UserID, Mailer, ss, CodeX, SendDataObj, StrSQL2, FetchedCats, StrSQL
if Request.QueryString("code" ) <> "" AND Request.QueryString("Email ") <> "" then 'code posted, process data
CodeX = Request.QueryString("code" )
EmailX = Request.QueryString("Email ")
Set GetDataObj = server.CreateObject("GetDa ta.in")
StrSQL = "Select * From NewsTable Where ISActive = 0 AND EmailAddress = '" & trim(EmailX) & "' And CodeSent = '" & trim(CodeX) & "'"
FetchedCats = GetDataObj.GetRS(StrSQL)
If IsObject(GetDataObj.GetRS( StrSQL)) Then
Set FetchedCats = GetDataObj.GetRS(StrSQL)
If FetchedCats.BOF And FetchedCats.EOF Then
ErrStr = "-Your email is not in the database or is active already."
Set FetchedCats = nothing
Set GetDataObj = nothing
else
UserID = FetchedCats("ID")
'Destroy old instance to Update database
Set FetchedCats = nothing
Set GetDataObj = nothing
Set SendDataObj = server.CreateObject("XData .up")
StrSQL = "UPDATE NewsTable Set ISActive = 1, DateActive = GetDate() Where ID = " & UserID
ErrStr = SendDataObj.GetRS(StrSQL)
Set SendDataObj = nothing
'check for dumped error
If instr(1,lcase(ErrStr),"err or") = 0 then ErrStr = "Thank you, you will receive our news soon"
end if
Else
ErrStr = GetDataObj.GetRS(StrSQL)
Set GetDataObj = nothing
End If
%>
<html>
<head>
<title>Activate your newsletter</title>
</head>
<body marginwidth=0 marginheight=o topmargin=0 leftmargin=0>
<form method=post name="NewsSub" action="newssubscribe.asp" >
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="100%" id="AutoNumber23" height="20" bgcolor="#E5E5E5">
<td width="100%" bgcolor=white>
<p style="margin-left: 25"><font face="Arial" size="2" color="Red">
<center><b><u>Status:</u>< br><%=ErrS tr%></b></ center></f ont><br><c enter><inp ut type="Button" Value="Close this window" OnClick="JavaScript:window .close()"> </center>
</td>
</tr>
<tr>
</table></form>
</body>
</html>
<%
else
EmailX = trim(Request.Form("frmEmai l"))
NameX = trim(Request.Form("frmName "))
NewsAlso = Request.Form("frmNewsAlso" )
if request("frmSubmit") <> "" then
if NameX = "" then ErrStr = "- Please type your name.<br>"
if EmailX = "" then ErrStr = ErrStr & "- Your Email must not be empty.<br>"
if NameX <> "" And Instr(1,NameX," ") = 0 then ErrStr = ErrStr & "- Type your full name.<br>"
if EmailX <> "" And (Instr(1,EmailX,"@") = 0 Or Instr(1,EmailX,".") = 0) then ErrStr = ErrStr & "- Type a valid email.<br>"
if NewsAlso = "" then NewsAlso = 0
'check if there's already such an email
If ErrStr = "" then 'process data
Set GetDataObj = server.CreateObject("GetDa ta.In")
StrSQL = "Select * From NewsTable Where EmailAddress = '" & trim(EmailX) & "'"
FetchedCats = GetDataObj.GetRS(StrSQL)
If IsObject(GetDataObj.GetRS( StrSQL)) Then
Set FetchedCats = GetDataObj.GetRS(StrSQL)
If FetchedCats.BOF And FetchedCats.EOF Then
'no record found
else
ErrStr = "-Such an email is already in the db"
End If
Set FetchedCats = nothing
Else
ErrStr = GetDataObj.GetRS(StrSQL)
End If
Set GetDataObj = nothing
end if
If ErrStr = "" then 'process data
'Generate activation code
randomize
CodeX = fix(rnd(5)*10000000000)
'Log to db
Set SendDataObj = server.CreateObject("XData .up")
StrSQL2 = "INSERT INTO NewsTable (EmailAddress, Name, IpLogged,CodeSent, XNews) Values ('" & trim(EmailX) & "','" & NameX & "','" & request.ServerVariables("R EMOTE_ADDR ") & "','" & trim(CodeX) & "'," & NewsAlso & ")"
ErrStr = SendDataObj.GetRS(StrSQL2)
Set SendDataObj = nothing
'Send confirmation email
If ErrStr <> "" then
Set Mailer = Server.CreateObject("Persi ts.MailSen der")
Mailer.Host = "email.www.com"
Mailer.From = "newsconfirm@www.com"
Mailer.FromName = "News letter"
Mailer.Subject = "Confirm subscription"
Mailer.IsHTML = 1
Mailer.Body = "Dear " & NameX & "!<br><br>Click on the below link to activate your newsletter subscription<br><a href='http:\\www.com\news.asp?code=" & CodeX & "&Email=" & EmailX & "'>http:\\www.com\news.asp\newssubscribe.asp?code=" & CodeX & "&Email=" & EmailX & "</a><br><br><br>This email was requested via ip: " & Request.ServerVariables("R EMOTE_ADDR ")
Mailer.AddAddress EmailX
On Error resume next
ss = Mailer.Send
If Err.number <> 0 then
ErrStr = "Error:" & Err.Description
else
ErrStr = "Thank you, a message was sent to your email"
end if
Set Mailer = nothing
end if 'If ErrStr <> "" then
end if 'If ErrStr = "" then 'process data
end if 'if request("frmSubmit") <> "" then
%>
<html>
<head>
<title>Subscribe to the news letter</title>
</head>
<body marginwidth=0 marginheight=o topmargin=0 leftmargin=0>
<form method=post name="NewsSub" action="newssubscribe.asp" >
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="100%" id="AutoNumber23" height="20" bgcolor="#E5E5E5">
<tr>
<td width="100%" bgcolor=white>
<p style="margin-left: 25"><font face="Arial" size="2" color="#606060">
Please provide us with your email address and Name to subscribe to the newsletter</font>
</td>
</tr>
<tr>
<td width="100%">
<p style="margin-left: 25"><font face="Arial" size="2" color="#606060">
Name:</font><input type=text name="frmName" size=20 value="<%=NameX%>">
</td>
</tr>
<tr>
<td width="100%">
<p style="margin-left: 25"><font face="Arial" size="2" color="#606060">
Email:</font><input type=text name="frmEmail" size=35 value="<%=EmailX%>">
</td>
</tr>
<tr>
<td width="100%">
<p style="margin-left: 25"><input type=CheckBox name="frmNewsAlso" size=35 value=1 <%if (NewsAlso <> 0 or NewsAlso = "") then Response.Write " Checked"%>><font face="Arial" size="2" color="#606060">
I want to receive receive promotion email also.</font>
</td>
</tr>
<tr>
<td width="100%">
<p ><font face="Arial" size="2" color="#606060">
<center><input type=Submit name="frmSubmit" Value="Subscribe" style="background: #E5E5E5; color: 606060"></center></font>
</td>
</tr>
<tr>
<td width="100%" bgcolor=white>
<p style="margin-left: 25"><font face="Arial" size="2" color="Red">
<b><u><%If ErrStr <> "" then%>Status:<%end if%></u><br><%=ErrStr%></b ></font>
</td>
</tr>
<tr>
</table></form>
</body>
</html>
<%end if%>
An interaction as thunderchicken pointed is a good solution too but will require extra development from your side and interaction from the client..
here is the code of such a thing using aspemail component..
here's a code I wrote a while ago.. it uses components I wrote to fetch a send data to the database and the aspemail component..
<%
option explicit
Response.Buffer=true
Dim ErrStr, GetDataObj, EmailX, NameX, IsRsFetchedCats, NewsAlso, UserID, Mailer, ss, CodeX, SendDataObj, StrSQL2, FetchedCats, StrSQL
if Request.QueryString("code"
CodeX = Request.QueryString("code"
EmailX = Request.QueryString("Email
Set GetDataObj = server.CreateObject("GetDa
StrSQL = "Select * From NewsTable Where ISActive = 0 AND EmailAddress = '" & trim(EmailX) & "' And CodeSent = '" & trim(CodeX) & "'"
FetchedCats = GetDataObj.GetRS(StrSQL)
If IsObject(GetDataObj.GetRS(
Set FetchedCats = GetDataObj.GetRS(StrSQL)
If FetchedCats.BOF And FetchedCats.EOF Then
ErrStr = "-Your email is not in the database or is active already."
Set FetchedCats = nothing
Set GetDataObj = nothing
else
UserID = FetchedCats("ID")
'Destroy old instance to Update database
Set FetchedCats = nothing
Set GetDataObj = nothing
Set SendDataObj = server.CreateObject("XData
StrSQL = "UPDATE NewsTable Set ISActive = 1, DateActive = GetDate() Where ID = " & UserID
ErrStr = SendDataObj.GetRS(StrSQL)
Set SendDataObj = nothing
'check for dumped error
If instr(1,lcase(ErrStr),"err
end if
Else
ErrStr = GetDataObj.GetRS(StrSQL)
Set GetDataObj = nothing
End If
%>
<html>
<head>
<title>Activate your newsletter</title>
</head>
<body marginwidth=0 marginheight=o topmargin=0 leftmargin=0>
<form method=post name="NewsSub" action="newssubscribe.asp"
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="100%" id="AutoNumber23" height="20" bgcolor="#E5E5E5">
<td width="100%" bgcolor=white>
<p style="margin-left: 25"><font face="Arial" size="2" color="Red">
<center><b><u>Status:</u><
</td>
</tr>
<tr>
</table></form>
</body>
</html>
<%
else
EmailX = trim(Request.Form("frmEmai
NameX = trim(Request.Form("frmName
NewsAlso = Request.Form("frmNewsAlso"
if request("frmSubmit") <> "" then
if NameX = "" then ErrStr = "- Please type your name.<br>"
if EmailX = "" then ErrStr = ErrStr & "- Your Email must not be empty.<br>"
if NameX <> "" And Instr(1,NameX," ") = 0 then ErrStr = ErrStr & "- Type your full name.<br>"
if EmailX <> "" And (Instr(1,EmailX,"@") = 0 Or Instr(1,EmailX,".") = 0) then ErrStr = ErrStr & "- Type a valid email.<br>"
if NewsAlso = "" then NewsAlso = 0
'check if there's already such an email
If ErrStr = "" then 'process data
Set GetDataObj = server.CreateObject("GetDa
StrSQL = "Select * From NewsTable Where EmailAddress = '" & trim(EmailX) & "'"
FetchedCats = GetDataObj.GetRS(StrSQL)
If IsObject(GetDataObj.GetRS(
Set FetchedCats = GetDataObj.GetRS(StrSQL)
If FetchedCats.BOF And FetchedCats.EOF Then
'no record found
else
ErrStr = "-Such an email is already in the db"
End If
Set FetchedCats = nothing
Else
ErrStr = GetDataObj.GetRS(StrSQL)
End If
Set GetDataObj = nothing
end if
If ErrStr = "" then 'process data
'Generate activation code
randomize
CodeX = fix(rnd(5)*10000000000)
'Log to db
Set SendDataObj = server.CreateObject("XData
StrSQL2 = "INSERT INTO NewsTable (EmailAddress, Name, IpLogged,CodeSent, XNews) Values ('" & trim(EmailX) & "','" & NameX & "','" & request.ServerVariables("R
ErrStr = SendDataObj.GetRS(StrSQL2)
Set SendDataObj = nothing
'Send confirmation email
If ErrStr <> "" then
Set Mailer = Server.CreateObject("Persi
Mailer.Host = "email.www.com"
Mailer.From = "newsconfirm@www.com"
Mailer.FromName = "News letter"
Mailer.Subject = "Confirm subscription"
Mailer.IsHTML = 1
Mailer.Body = "Dear " & NameX & "!<br><br>Click on the below link to activate your newsletter subscription<br><a href='http:\\www.com\news.asp?code=" & CodeX & "&Email=" & EmailX & "'>http:\\www.com\news.asp\newssubscribe.asp?code=" & CodeX & "&Email=" & EmailX & "</a><br><br><br>This email was requested via ip: " & Request.ServerVariables("R
Mailer.AddAddress EmailX
On Error resume next
ss = Mailer.Send
If Err.number <> 0 then
ErrStr = "Error:" & Err.Description
else
ErrStr = "Thank you, a message was sent to your email"
end if
Set Mailer = nothing
end if 'If ErrStr <> "" then
end if 'If ErrStr = "" then 'process data
end if 'if request("frmSubmit") <> "" then
%>
<html>
<head>
<title>Subscribe to the news letter</title>
</head>
<body marginwidth=0 marginheight=o topmargin=0 leftmargin=0>
<form method=post name="NewsSub" action="newssubscribe.asp"
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="100%" id="AutoNumber23" height="20" bgcolor="#E5E5E5">
<tr>
<td width="100%" bgcolor=white>
<p style="margin-left: 25"><font face="Arial" size="2" color="#606060">
Please provide us with your email address and Name to subscribe to the newsletter</font>
</td>
</tr>
<tr>
<td width="100%">
<p style="margin-left: 25"><font face="Arial" size="2" color="#606060">
Name:</font><input type=text name="frmName" size=20 value="<%=NameX%>">
</td>
</tr>
<tr>
<td width="100%">
<p style="margin-left: 25"><font face="Arial" size="2" color="#606060">
Email:</font><input type=text name="frmEmail" size=35 value="<%=EmailX%>">
</td>
</tr>
<tr>
<td width="100%">
<p style="margin-left: 25"><input type=CheckBox name="frmNewsAlso" size=35 value=1 <%if (NewsAlso <> 0 or NewsAlso = "") then Response.Write " Checked"%>><font face="Arial" size="2" color="#606060">
I want to receive receive promotion email also.</font>
</td>
</tr>
<tr>
<td width="100%">
<p ><font face="Arial" size="2" color="#606060">
<center><input type=Submit name="frmSubmit" Value="Subscribe" style="background: #E5E5E5; color: 606060"></center></font>
</td>
</tr>
<tr>
<td width="100%" bgcolor=white>
<p style="margin-left: 25"><font face="Arial" size="2" color="Red">
<b><u><%If ErrStr <> "" then%>Status:<%end if%></u><br><%=ErrStr%></b
</td>
</tr>
<tr>
</table></form>
</body>
</html>
<%end if%>
u can put all the restricted characters in an array and u can use the function instr to find out the position of the a particullar character.if it is >0 then u can say invalid character.
Bye
Bye
listening
I have a working VB solution. How many days are you willing to invest, and are you fluent with VB?
ASKER
the launch date for the site is may the first, getting this particular aspect to work is quite a low priority but if I can get this done in that time it would be nice, my VB is fairly strong
I was asking because there are several techniques involved.
There is a working VB project at www9.brinkster.com/robbert /metageart oolz.zip
To test it, start in debug\group1.vbg.
It's tested with NT4 and NT5 (put your current %systemroot%\nslookup.exe into the App.Path).
Note: This is a set of > 20 components which have been tested with NT4 two years ago but some are not working with NT5 now, but EmailAdress is tested now.
As for the general techniques:
1. Extract the domain name from the email address.
2. Execute nslookup.exe and get its return value, to extract the mx record (mail exchanger). (Note: Actually, there may be more than one mail exchanger for an email address; this app retrieves the first one only.)
3. Connect to the mail exchanger via the HTTP protocol (using Winsock), following the SMTP protocol, sending and receiving something like:
[Contacting mx1.mail.yahoo.com [64.157.4.81]...]
[Connected]
220 YSmtp mta410.mail.yahoo.com ESMTP service ready
HELO hexillion.com
250 mta410.mail.yahoo.com
MAIL FROM:<HexValidEmail@hexill ion.com>
250 sender <hexvalidemail@hexillion.c om> ok
RCPT TO:<mypersonalaccount@yaho o.com>
250 recipient <mypersonalaccount@yahoo.c om> ok
QUIT
221 mta410.mail.yahoo.com
[Connection closed]
Actually, this is like sending an email but not sending its contents. Find more information on that in the Internet Mail section of http://www.vbip.com/winsock/index.asp
There is a working VB project at www9.brinkster.com/robbert
To test it, start in debug\group1.vbg.
It's tested with NT4 and NT5 (put your current %systemroot%\nslookup.exe into the App.Path).
Note: This is a set of > 20 components which have been tested with NT4 two years ago but some are not working with NT5 now, but EmailAdress is tested now.
As for the general techniques:
1. Extract the domain name from the email address.
2. Execute nslookup.exe and get its return value, to extract the mx record (mail exchanger). (Note: Actually, there may be more than one mail exchanger for an email address; this app retrieves the first one only.)
3. Connect to the mail exchanger via the HTTP protocol (using Winsock), following the SMTP protocol, sending and receiving something like:
[Contacting mx1.mail.yahoo.com [64.157.4.81]...]
[Connected]
220 YSmtp mta410.mail.yahoo.com ESMTP service ready
HELO hexillion.com
250 mta410.mail.yahoo.com
MAIL FROM:<HexValidEmail@hexill
250 sender <hexvalidemail@hexillion.c
RCPT TO:<mypersonalaccount@yaho
250 recipient <mypersonalaccount@yahoo.c
QUIT
221 mta410.mail.yahoo.com
[Connection closed]
Actually, this is like sending an email but not sending its contents. Find more information on that in the Internet Mail section of http://www.vbip.com/winsock/index.asp
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the help, I havnt implemented the code yet but it has definatly put me on the right way,
cheers
joe
cheers
joe
you can buy a cheap component here..(50$)
http://www.serverobjects.com/products.htm#aspmx
But if you want to do it yourself then you will need to do an nslookup .. use aspexec from www.serverobjects.com to execute a shell.. or use the wsh shell object..
also an easy and practical way you can use xmlhttp to post an fetch such data from www.network-tools.com .. when you get the data in you variable search for the info after the validation results word:
Validation results
Success <----
canonical address: <sakr_m@hotmail.com>
MX records preference exchange IP address (if included)
5 mx08.hotmail.com [64.4.49.7]
5 mx07.hotmail.com [65.54.236.7]
5 mx06.hotmail.com [64.4.55.7]
5 mx05.hotmail.com [64.4.56.199]
5 mx04.hotmail.com [64.4.56.135]
....
How do I read the contents of a remote web page?
You can include static txt and HTML files from remote servers by using a component (such as AspHTTP (http://www.serverobjects.com/products.htm), ASPTear (http://www.alphasierrapapa.com/ComponentCenter/AspTear/), or VB's built in InetCtrls) to parse the remote URL's content.
You can also try this method out, it uses the MSXML objects which are installed with Windows 2000 (or you can download them here (http://download.microsoft.com/download/xml/Install/3.0/WIN98Me/EN-US/msxml3.exe) for other operating systems):
<%
url = "http://www.espn.com/"
set xmlhttp = server.CreateObject("Micro
xmlhttp.open "GET", url, false
xmlhttp.send ""
Response.write xmlhttp.responseText
%>