CFLib.org – Common Function Library Project

verifyEmail(emailAddress)

Last updated July 15, 2009

author

Craig Kaminsky

Version: 3 | Requires: CF6 | Library: UtilityLib

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

Return Values:
Returns a structure.

Example:

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

Parameters:

Name Description Required
emailAddress Address to validate. Yes

Full UDF Source:

/**
 * 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;
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson