This service has been free and unlimited for a couple of years now but unfortunately we will have to add some limitations. From August 22nd 2008 onward free use will be limited to 20 validations per day. We are also setting up a pay program via paypal for users who want to continue using the service at a higher level. A payment process will be setup shortly. Check back for details, or contact us at editor(at)bestcodingpractices.com. Sorry for any inconvenience this may cause





Email validation is one of the most common forms of data validation and one of the most incorrectly validated. We are not going to share yet another semi-complete regular expression string to validate emails and we�re not going to compare the benefits of client side vs. server side email validation. Instead we�re going to look at a real solution.



When sending out email newsletters, or site notifications we often find that many of the addresses are bounced back at us. Maybe at one time these were valid email addresses, but their owners have closed accounts, or simply stopped using them for so long that they have been removed. The best solution to this problem is to validate these addresses before sending an email. We�re not talking about simple syntax validation as all of your emails probably pass syntax validation. We want to know if that mailbox is open for business. In order to do that a request has to be sent to the SMTP server querying for the mailbox. This method of validation is much more effective than syntax validation and much more automated than taking bounced emails off your list by hand.



There are a few methods out there for doing this and it is a fairly complicated process. One of the easiest methods to use is a email validation service. We have one setup here at BestCodingPractices for you.



The service accepts either a GET or POST operation with a comma separated list of up to 10 email addresses called �email� and a validation level called �level�. The validation levels are �syntax� which is there only for fun. �domain� level validation checks that the domain referenced from the email address exists. �smtp� level validation checks that the domain referenced has an SMTP service running on it. Finally the cream of the crop, �mailbox� validation checks that the SMTP service has a mailbox for the specific email address you�re using.



An example of using the service from PHP would look like this (please replace the (at) string with an actual @):

Code: <?php

$validEmail = array();

$XMLurl = "http://www.bestcodingpractices.com/email_verification/e-verify.asp?email=editor (at) bestcodingpractices.com,not (at) bestcodingpractices.com&level=mailbox";

$XMLDOC = new DOMDocument();

$XMLDOC->preserveWhiteSpace = false;

if ($XMLDOC->load($XMLurl))

{

$XMLpath = new DOMXPath($XMLDOC);

$mailNodes = $XMLpath->query('/validation')->item(0);

foreach ($mailNodes->childNodes as $mail)

{

$validEmail[ $mail->getAttribute('address') ] = $mail->getElementsByTagName("success")->item(0)->nodeValue;

}

unset($XMLpath);

}

print_r($validEmail);

?>



This code will check the 2 email addresses �editor(at)bestcodingpractices.com� and not(at)bestcodingpractices.com. Not surprisingly �not(at)bestcodingpractices.com� is NOT at bestcodingpractices.com while EDITOR is.



From ASP your code would look more like (again notice the (at) needs replaced with @):

Code: <%

Dim objXml, objTemp, node, url



url = "http://www.bestcodingpractices.com/email_verification/e-verify.asp?email=editor (at) bestcodingpractices.com,not (at) bestcodingpractices.com&level=mailbox"



Set objXml = Server.CreateObject("Msxml2.DOMDocument.3.0")

objXml.async = False

objXml.loadXML(getURL(url))



If objXML.parseError.errorCode <> 0 Then

response.write objXML.parseError.reason & "<br/>" & objXML.parseError.errorCode

response.write "<br/>Please try your request again.<br/>" & url

response.end

End If



set objTemp = objXML.SelectNodes("validation/email[success=1]")

response.write "Valid Email Addresses: <br/>"

for each node in objTemp

response.write "<b>" & node.Attributes.getNamedItem("address").Text & "</b><br/>"

response.write " Syntax: " & node.selectSingleNode("syntax").text & "<br/>" &_

" Domain: " & node.selectSingleNode("domain").text & "<br/>" &_

" SMTP: " & node.selectSingleNode("smtp").text & "<br/>" &_

" Mailbox: " & node.selectSingleNode("mailbox").text & "<br/>"

next

set objTemp = objXML.SelectNodes("validation/email[success=0]")

response.write "<p>"

response.write "Invalid Email Addresses: <br/>"

for each node in objTemp

response.write "<b>" & node.Attributes.getNamedItem("address").Text & "</b><br/>"

response.write " Syntax: " & node.selectSingleNode("syntax").text & "<br/>" &_

" Domain: " & node.selectSingleNode("domain").text & "<br/>" &_

" SMTP: " & node.selectSingleNode("smtp").text & "<br/>" &_

" Mailbox: " & node.selectSingleNode("mailbox").text & "<br/>"

next

set objTemp = nothing

set objXML = nothing



Function getURL(url)

On Error Resume Next

Set http = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")

http.open "GET", url, true

http.send

If http.readyState <> 4 then

http.waitForResponse 10

End If

If Err.Number = 0 AND http.Status = 200 then

getURL=http.responsetext

else

getURL=""

end if

set http = nothing

End Function

%>



Either example is going to return this response from the service:

Code: <?xml version="1.0" ?>

<validation>

<email address="editor(at)bestcodingpractices.com">

<syntax>1</syntax>

<domain>1</domain>

<smtp>1</smtp>

<mailbox>1</mailbox>

<success>1</success>

</email>

<email address="not(at)bestcodingpractices.com">

<syntax>1</syntax>

<domain>1</domain>

<smtp>1</smtp>

<mailbox>0</mailbox>

<success>0</success>

</email>

</validation>



Each email sent will return a validation result for each level of validation conducted. Each successive level of validation is inclusive of the ones before it. If a level of validation is not reached the XML will contain an empty tag for that level. For instance the same request with only domain level validation would return the following results:

Code: <?xml version="1.0" ?>

<validation>

<email address="editor(at)bestcodingpractices.com">

<syntax>1</syntax>

<domain>1</domain>

<smtp />

<mailbox />

<success>1</success>

</email>

<email address="not(at)bestcodingpractices.com">

<syntax>1</syntax>

<domain>1</domain>

<smtp />

<mailbox />

<success>1</success>

</email>

</validation>



Notice the SMTP and Mailbox nodes are empty because no check was done. Also the Success node is now positive for both tests because even the spurious email address �not(at)bestcodingpractices.com� does pass domain level validation and would also pass SMTP validation. Only when all checks are accomplished do we find that this is not a valid email.



When in a production environment you may need to take time into consideration. Each SMTP server will have its own response time and validating 10 emails with slow SMTP servers could take more time than you are able to commit. In cases like this it would obviously be better to send fewer emails or use a lower level of validation.



Please feel free to use this service from your site. You can validate emails one at a time, or up to 10 emails at a time. We are planning on leaving free access to this service if we are able. If you are interested in the service and have any special requirements or have any trouble implementing this on your site please contact us at support(at)beachbumsoftware.com



Sorry... the service has been taken down for the time being. We had to move servers and it's causing trouble. We'll get it back up and running as soon as possible. Comments : etmoreno 2006-09-07 #49 Hi Travis, you service is amazing...

Congratulations !!!

I like to have e-verify.asp code.

Is this posible?

I need to modify it for second level addresses, like: info@etmoreno.com.ar for example.

Best regards

etmoreno BeachBum 2006-09-07 #50 Thanks for using the service.

The online service does not have any problem handling next level email addresses so I tested your email address and found that the SMTP server was taking a long time to respond so I upped the timeout on the demo to 45 seconds. That should be plenty of time for a server to respond.



You did give me a good idea for an upgrade to the service though. I will add a timeout value that will cause the service to return an "unavailable" response object so your code can deal with that as it wants to. The address could be put on a "Check again" list or something.



I'll make a note here when that is accomplished.

Thanks

Travis jeffc 2007-04-25 #59 Hi Travis,



Thank you for the email validator -- I'm always amazed at the effort that folks are willing to put into making the web an easier place to work, and your validator is a great example.



I wanted to point out a problem that we've run into using the validator. It started last night, after we'd successfully used it for some testing. We're getting an error: "error '8007000e' /email_verification/e-verify.asp, line 68 ", in response to:



http://www.bestcodingpractices.com/email_verification/e-verify.asp?email=editor@bestcodingpractices.com&level=mailbox



Jeff BeachBum 2007-05-04 #60 Hey Jeff,



Thanks for using the tool. I'm sorry you were getting errors but I can't seem to reproduce them. I tried the link you posted and it is working. I ran the whole thing through some tests, that why it took me so long to write back and I can't find a problem.



If it happens again let us know. In fact if anyone has a problem with this tool please email us right away at editor(at)bestcodingpractices.com



Thanks hapadilo 2007-09-23 #64 hi Travis,



there is a minor error with the result returned by the service.

it returns invalid xml when email is empty and that causes xml parsing errors.

when email value is empty <email/> is printed at the end instead of a closing tag </email>.

everything else seems ok, thanks for the great service.



Carlos BeachBum 2007-09-24 #65 Thanks Hapadilo,



I've fixed it on the live service so you should not have any more trouble with that. Anonymous 2008-03-21 #67 2008-03-21 #67 Testing your email validation service and I receive this error:



XML document must have a top level element.

-1072896680

Please try your request again.

http://www.bestcodingpractices.com/email_verification/e-verify.asp?email=maryanaburtea@yahoo.com&level=Mailbox



Thanks,

Steve BeachBum 2008-03-21 #69 Hey Steve,



The url you posted worked fine for me. Can you give a little more information about what you're doing? Are you consuming the service from ASP, PHP, .NET? Or were you just testing the above URL in your browser? Alex 2008-03-24 #75 2008-03-24 #75 Hi! I'm trying the script off my website, (I've got a page I'm working on under test) and I get the exact same error as Anonymous above.



The script worked fine and correctly first time, but all subsequent instances of trying,with valid or invalid addresses yield the same result :-(



I'm working in ASP if that helps?

Thanks for any info - your site and script it otherwise excellent, and is just what I'm after for the occasional email address I get! BeachBum 2008-03-26 #78 Thanks Alex,



It sounds like you, and anonymous are both getting a blank response back which would be the case if the call has a timeout. How many email addresses were you sending for validation? The timeout is currently set for 30 seconds, we don't want it too much longer than that or it will start dragging down our servers. Try sending just 1 email for testing, if that isn't the problem then please send me your code and I'll take a look. Anonymous 2008-03-26 #79 2008-03-26 #79 Hi, Beachbum! I was just sending the one address for checking - and each occasion I try, I get a correct response the first time, then the error as indicated above on the second and subsequent attempt.



If I wait a few hours, and go again, I get 1 correct response, then errors after. :-(



Just tried it again, same outcome.

I'll send you my code via email - I don't think there's anything amiss, but I'm not an expert!

Thanks! Alex. BeachBum 2008-03-27 #97 Alex,



I can't reproduce this error. Can you email me the code at travis (at) beachbumsoftware.com



I had to turn off the anonymous posting because someone was spamming me, I'll turn it back on when they get tired of it.



Feel free to setup an account to post comments. We never send solicitation emails, too busy to bother with it BeachBum 2008-04-12 #98 Alex,



I never saw an email from you. Please email it again if you're still working on it. I've turned the anonymous posting back on for a bit. Hope to hear from you. sperch 2009-01-21 #400 Thanks for the great tool.



I've been using it without problems until yesterday. Any address that I test comes back as bad, including editor@bestcodingpractices.com



Is this a temporary system problem or am I doing something wrong?



-SB

Search For Articles

