This code offers a very simple way to track emails and see whether or not they have been displayed by the recipient. Because this technique does not put a query string after an image, it is undetectable by spam engines, making it appropriate for legitimate newsletters etc that you want to track without being spam blocked.
Tracking emails by logging the request for an image is a commnonly used technique. This example varies from many in that it does not need a query string after the image to send back information about the user e.g.
someimage.gif?userdata=12345 which is easilly spotted by antispam engines.
Instead this method stores the user data in the name of the image i.e.
myLogoUser12345.gif which is indistinguishable from any other image request.
In order to use this technique we must re-configure IIS to call our page instead of the standard 404 page not found. Whenever a rqeuest comes for a gif- image that does not exist we log that request and return a logo or in this case a transparent 8x8 pixel gif.
Using the Code
simply put the following code in a page called 404.aspx, set up your access database (or change for sql if you have a sql server at your displosal) and you can start tracking.
To track an email, simply include a remote image in your message. The remote image in the email points to an image on your server. The trick is that the image MUST NOT ACTAULLY EXIST. This causes our custom 404 handler to be called. Our custom handler then returns a transparent 8x8 pixel gif, and the request is logged in a database.
<%@ Page Language="VB" %>
' this page is configured in IIS to replace the standard 404 page not found page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim sa As String
' at this point we already know the page / file does not exist, now we check to see
' if a gif was requested
If Request.Url.ToString.EndsWith(".gif") Then
' first we return the invisible 8x8 gif trtr.gig
Response.ContentType = "image/gif"
'next we log the request in our database, the name of the gif forms our tracking data
sa = Request.Url.ToString.Remove(0, Request.Url.ToString.LastIndexOf("/") + 1)
sa = sa.Replace(".gif", "")
Dim ads As New AccessDataSource
' replace this with the location of you writeable database
ads.DataFile = "D:\websites\thear1\data\campaign.mdb"
ads.InsertCommand = "INSERT INTO [tracking] ([keyword], [time], [date], [url], [referer]) VALUES (?, ?, ?, ?, ?)"
' the missing file / page was not a gif, so return as page not found message
sa = Request.Url.ToString.Remove(0,
Request.Url.ToString.LastIndexOf("/") + 1) Response.Write("Page " &
sa & " does not exist ")
Changing IIS to use your Page for 404 Requests
If you do not have access to your own server, then you will need to ask your hosting copmany to point your 404 page not found page to your custom 404.aspx page (which most companies will do without issue)
Launch inetmgr then go to the custom errors tab and modify the 404 entry