Saturday, January 2, 2010

Email Verification integration for CRM via free Web Service

Email address plays a very important role in CRM.  Take one for example, synchronization of Contact records and activities between CRM and Outlook is heavily relying on contact email address as the common identifier.  Also,  email address is commonly used as the unique identifier for duplicate detection rules for Contact and Lead records.  More over, my company’s Marketing and Sales teams are doing more and more email marketing these days.  And it is very important that email addresses get verified before email marketing communications are sent. 
For all these reasons above, I have always wanted an email verification functionality in CRM, and I did my research to find cost-effective ways to implement the feature.  However, email verification service providers such as Melissa Data, StrikeIron, CDYNE, TowerData all come with annual cost of thousands of dollars.  And due to the recent economic crisis, my company is putting a freeze on all IT capital budgets.  So I have to find free or cheaper ways to get this done.
Until recently, I stumbled upon a free web service provider called “WebserviceX.NET” .  And luckily, one of the web service it hosts is a email verification service.  I was so excited, and jumped right on it to integrate it into my company’s CRM system.  At  first, following the example in this article, I added a inline toolbar button on the Lead and Contact forms to provide one-click access to verify email address on the fly.  And then added the client side web service call function to do the actual email verification, and update the result back to the Lead or Contact record.  Here are excerpts of the code and a screenshot of it.

// add inline toolbar for email verification
    window.GeneralToolbar = new InlineToolbar("new_inlinetoolbar");
    GeneralToolbar.AddButton("btnVerifyEmail","Verify This Email","15%",ValidateEmail);
    // attach the ValidateEmail function to the OnChange event to the "Email Address" field
    field = document.getElementById("emailaddress1");
    field.attachEvent( "onchange" , ValidateEmail );
function ValidateEmail()
{
// if email address field is changed with new value, call web service to validate it
// and log the new result and timestamp
// var field = event.srcElement;
if( crmForm.all.emailaddress1.DataValue == null ) return;
document.body.style.cursor = 'wait';
var email = crmForm.all.emailaddress1.DataValue;
var validemail = ValidateEmailWebService(email);
crmForm.all.new_emailstatus.ForceSubmit = true;
crmForm.all.new_emailverifiedon.ForceSubmit = true;
crmForm.all.new_emailverifiedon.DataValue = new Date();
if (validemail=="true")
    {
        crmForm.all.new_emailstatus.DataValue = "Good";
    }
else if (validemail=="false")
    {
        crmForm.all.new_emailstatus.DataValue = "Bad";
    }
document.body.style.cursor = 'default';
}
function ValidateEmailWebService(email)
{
var soapBody = "<soap:Body><IsValidEmail xmlns='http://www.webservicex.net'><Email>" + email + "</Email></IsValidEmail></soap:Body>";
soapXml += soapBody;
soapXml += "</soap:Envelope>";
var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
xmlhttp.open("POST", serverUrl+ "/ValidateEmail.asmx", false);
xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlhttp.setRequestHeader("SOAPAction", "http://www.webservicex.net/IsValidEmail");
xmlhttp.send(soapXml);
xmlDocUser=new ActiveXObject("Microsoft.XMLDOM");
xmlDocUser.async=false;
xmlDocUser.loadXML(xmlhttp.responseXML.xml);
var result = xmlDocUser.getElementsByTagName("IsValidEmailResult")[0].childNodes[0].nodeValue;
return result;
}

image