Email validation in VBA
February 22, 2010 • JP • 4 Comments • Rate This Article![]()
I found another website that lists web services you can consume in your VBA applications. WebserviceX.net
provides On Demand XML Web Services for Financial,Distribution, Retail, Health Care, Manufacturing, Telecom, Government and Educational Industry.
What this means for you is more stuff to do. Well, more stuff for your applications to do.
Let's use one web service: validating email addresses. I'm not talking about the formatting, but actually checking if the email address can be mailed.
The API at WebserviceX explains how to use it. Here's how the code works out:
Dim xml As Object
Dim result As String
Set xml = CreateObject("MSXML2.XMLHTTP")
xml.Open "GET", "http://www.webservicex.net/ValidateEmail.asmx/IsValidEmail?Email=" & emailAddress, False
xml.Send
result = xml.responsetext
' parse result for response
IsValidEmail = (InStr(result, "true") > 0)
End Function
The XML response looks like this:
<boolean xmlns="http://www.webservicex.net">true</boolean>
The service returns true if the email address is valid; false if it isn't. So all we have to do is check for those in the result.
Sample usage
Debug.Print IsValidEmail("asdf@asdf.com")
End Sub
I wonder, though, if this is a legit use for VBA?
↑ Scroll to topPrevious Post: Display New Mail Desktop Alerts for specific senders
Next Post: Now soliciting guest posts



Why isn't this a reasonable use for VBA?
I can imagine some lowly spammer using it to validate email addresses. But I suppose they can do it without my help.
I like this. Thanx for finding this.
Thanks JP for another great post. Some Access Database users send emails to their customers and this code could be quite helpful for maintaining a list of valid email addresses.