
Looking to post your email address on Twitter or on your website, but keep it away from the spammers? Here's one way using a neat API I found last week.
One of my favorite WordPress plugins is Who Sees Ads, which I use to selectively display ads and other content on this site. I highly recommend it if, for example, you only want search engine visitors to see your newsletter signup form.
Anyway, the plugin author has a website that lets you obfuscate your email address in a unique way. The site is called Scr.im and here is the rationale:
Leaving your email as plain text in forums, on Twitter or on classified sites makes you an easy spam target: spam robots and email harvesters constantly browse these sites to collect new victim emails.
Don't share your email on public sites. Instead, use our free service that will convert your email address (joe@email.com) into a safe and short URL (for instance http://scr.im/joe). People willing to email you will go to this URL that will reveal your email address, after a simple test that automated scripts and bots cannot pass.
Scr.im has an API that requires a POST request with your email address, as well as a (optional) keyword for a custom alias. So I wrote a VBA function that calls the scr.im website and returns the URL for you to use instead of your email address.
Scr.im that email!
The following function calls the scr.im API and caches the response. It uses MSXML6.DLL which should be located in the local SYSTEM32 folder. I've decided to upgrade all my old code to use MSXML6.DLL because it is included with Windows Vista, 7 and later versions of XP, so most people using Windows should have it (whereas MSXML2.DLL is missing from my Vista laptop). However you do not need any early bound references for this code to work.
The response is cached because if you call the API with the same email address, you get the same response (i.e. you don't get a new URL). Plus, in keeping with best practice, we don't want to overload the API with useless repeated calls. Besides, if you want to change your custom alias, you can't do it programmatically.
POST request syntax courtesy of Excel Geek.
Function GetScrim(emailAddress As String, Optional scrimKeyword As String, _
Optional forceRequery As Boolean = False) As String
' http://scr.im/api/
Dim xml As Object ' MSXML2.XMLHTTP
Dim xmlDoc As Object ' MSXML2.DOMDocument
Dim xmlDocRoot As Object ' MSXML2.IXMLDOMNode
Dim url As Object ' MSXML2.IXMLDOMNode
Dim result As String
Dim tempFile As String
Const XML_FILE_EXTENSION As String = ".xml"
Const BASE_URL As String = "http://scr.im/xml/"
tempFile = environ("temp") & "\" & emailAddress & XML_FILE_EXTENSION
If Len(Dir(tempFile)) = 0 Or forceRequery Then
Set xml = GetMSXML
With xml
.Open "POST", BASE_URL, False
.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
If Len(scrimKeyword) > 0 Then
.send "email=" & emailAddress & "&scrim=" & URLEncode(scrimKeyword)
Else
.send "email=" & emailAddress
End If
End With
result = xml.responseText
' save result as temp XML document
tempFile = CreateFile(tempFile, result)
End If
' load XML file into new XML document
Set xmlDoc = CreateObject("MSXML2.DOMDocument.6.0")
With xmlDoc
.async = False
.validateOnParse = False
.Load tempFile
End With
' check that the XML doc loaded
If LoadError(xmlDoc) Then
Exit Function
End If
' get root node
Set xmlDocRoot = GetRootNode(xmlDoc)
' get last node, return error code if applicable
Set url = GetNode(xmlDocRoot, xmlDocRoot.childNodes.Length)
GetScrim = url.nodeTypedValue
End Function
Helper Functions
These helper functions are used by the above function. Paste them into a standard module in the same project. You'll also need the URLEncode function courtesy of Free VB Code.
Notice that our function does not validate email address, which you might want to incorporate. Also, you'll need to check the output of the function to look for error messages; anything other than a URL is an error message.
Sample Usage
Here's Joe's URL:
Sub ScrimThis()
Debug.Print GetScrim("joe@email.com", "joe")
End Sub
Follow Me