Solved

Email address validation

Posted on 2002-04-05
11
319 Views
Last Modified: 2007-12-19
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
0
Comment
Question by:joe_g99
  • 3
  • 3
  • 2
  • +3
11 Comments
 
LVL 20

Expert Comment

by:Silvers5
Comment Utility
it's difficult to develope your own:

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("Microsoft.XMLHTTP")
    xmlhttp.open "GET", url, false
    xmlhttp.send ""
    Response.write xmlhttp.responseText
%>

0
 
LVL 20

Expert Comment

by:Silvers5
Comment Utility
0
 
LVL 11

Expert Comment

by:thunderchicken
Comment Utility
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
0
 
LVL 20

Expert Comment

by:Silvers5
Comment Utility
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("GetData.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),"error") = 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><%=ErrStr%></b></center></font><br><center><input type="Button" Value="Close this window" OnClick="JavaScript:window.close()"></center>
             </td>
            </tr>
        <tr>
      </table></form>
      </body>
      </html>



<%

else
      EmailX = trim(Request.Form("frmEmail"))
      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("GetData.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("REMOTE_ADDR") & "','" & trim(CodeX) & "'," & NewsAlso & ")"
                  ErrStr = SendDataObj.GetRS(StrSQL2)
                  Set SendDataObj = nothing

'Send confirmation email
                        If ErrStr <> "" then
                              Set Mailer = Server.CreateObject("Persits.MailSender")
                              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("REMOTE_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%>
0
 

Expert Comment

by:N_K_venkat
Comment Utility
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
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 5

Expert Comment

by:kcm76
Comment Utility
listening
0
 
LVL 15

Expert Comment

by:robbert
Comment Utility
I have a working VB solution. How many days are you willing to invest, and are you fluent with VB?
0
 

Author Comment

by:joe_g99
Comment Utility
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
0
 
LVL 15

Expert Comment

by:robbert
Comment Utility
I was asking because there are several techniques involved.

There is a working VB project at www9.brinkster.com/robbert/metageartoolz.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@hexillion.com>
250 sender <hexvalidemail@hexillion.com> ok
RCPT TO:<mypersonalaccount@yahoo.com>
250 recipient <mypersonalaccount@yahoo.com> 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
0
 
LVL 15

Accepted Solution

by:
robbert earned 200 total points
Comment Utility
Probably, there is no objective against claiming this question, and bookmarking it.
As the questioner told, this is within his scope of technology (using VB).
The solution has been tested thoroughly with NT4 and NT5.
If there are further questions I'ld like to answer them (being aware that this is a field that comprises several advanced VB techniques) - otherwise, I'ld just like to claim to have put you on the right way.

Thank you.
0
 

Author Comment

by:joe_g99
Comment Utility
Thanks for the help, I havnt implemented the code yet but it has definatly put me on the right way,

cheers

joe
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Classic ASP + JS 4 67
JQuery Date Time picker not showing 29 92
Dreamweaver server behavior gone 6 71
INNER JOIN ? 8 29
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now