CFLib.org – Common Function Library Project

verifyEmail(emailAddress)

Last updated July 15, 2009

Version: 3 | Requires: ColdFusion MX | Library: UtilityLib

 
Rated 9 time(s). Average Rating: 4.2

Description:
This function validates the existence of an email address via the ValidateEmail Web Service at webservicex.net.

Return Values:
Returns a structure.

Example:

view plain print about
<cfset result = verifyEmail("myemail@thisisnotarealdomainihope.com")>
<cfdump var="#result#">

Parameters:

Name Description Required
emailAddress Address to validate. Yes

Full UDF Source:

view plain print about
<cfscript>
/**
 * Validate an email existence using an external web service.
 * v2 mods by Raymond Camden
 * 
 * @param emailAddress      Address to validate. (Required)
 * @return Returns a structure. 
 * @author Craig Kaminsky (imageaid@gmail.com) 
 * @version 3, July 15, 2009 
 */

function verifyEmail(emailAddress){
    // local variables
    var email_address = Trim( arguments.emailaddress );
    var results = StructNew();
    var validationResponse = "";
    var ws = "";
    // add the default keys and values for returned struct 
    results.wsdl = "http://www.webservicex.net/ValidateEmail.asmx?wsdl";
    results.attemptTime = Now();
    // setup the web service
    ws = createObject( "
webservice", results.wsdl );
    // ensure, first, that we have a properly formatted email address
    if( IsValid( "
email", email_address )) {
        // setup some exception handling just in case the Web Service is down, etc.
        try
        {
            validationResponse = ws.IsValidEmail( Email=email_address );
        }
        catch( Any err )
        {
            results.emailResult = false;
            results.message = "
Web Service response error: " + err.Message;
            results.resultCode = "
fail";
            // exit the function and return the results struct
            return results;
        }            
        // check the response from the web service
        if( Ucase(Trim( validationResponse )) is "
YES" )
        {
            results.emailResult = true;
            results.message = "
Email address passed validation and verification.";
            results.resultCode = "
valid";
        }
        else
        {
            results.emailResult = false;
            results.message = "
Email address passed validation but failed verification.";
            results.resultCode = "
invalid";
        }
    }
    else
    {
        results.emailResult = false;
        results.message = "
Email address failed validation. It is not properly formatted.";
        results.resultCode = "
invalid";
    }
    return results;
}
</cfscript>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Adam Cameron Adam Cameron added
savecontent
24 day(s) ago

Pete Ruckelshaus Pete Ruckelshaus added
firstDayOfWeek
a while ago

Chris Weller Chris Weller added
convertQueryStri...
a while ago

Dan Bracuk Dan Bracuk added
getExcelPercenti...
a while ago

Top Rated

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 42 time(s)

Barney Boisvert indentXml
Rated 5.0, 12 time(s)

Rachel Lehman deAccent
Rated 5.0, 8 time(s)

Markus Schneebeli                                 ListRemoveByStri...
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson