Click here to Skip to main content
13,803,717 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


35 bookmarked
Posted 15 Jan 2009
Licenced CPOL

Get Notified When Client Opens Email

, 15 Jan 2009
Rate this:
Please Sign up or sign in to vote.
In this article we learn how to create a simple HttpHandler that will notify the sender when the email is opened.


So, you had a fight with your girlfriend and she is not taking your phone calls. You left countless messages but she never replied. You sent her emails but have no idea that if she checked them or not. In these situations it will be a good idea to get a notification when your girlfriend has opened her email. This will give you a little piece of mind that at least she is reading your emails. Let's see how we can implement this functionality.

Basic Idea

The basic idea is to embed a very small invisible image in the email. The image will contain a GUID as a query string. The image is downloaded by the client which makes a request back to the server and sends the query string. The query string is extracted and the field in the database is updated indicating that the user has checked the email.

Creating an Invisible Image

You can create a very small image with a white background. This can be as small as a dot. In this article we have made the image larger so that you will have a better idea of what we are talking about. Take a look at the image below:


The image above also contains the red dot. The red dot is only used so that you will have a better idea where the image is displayed. In actual production code you will use a much smaller image.

Attaching a GUID with Image

The next step is to attach a Guid as a query string with the image. In production code this Guid will come from a database table which will be used to track which user has checked their email and which has not but in this case we will be creating a dummy Guid. Take a look at the following code which attaches a Guid with the image URL as a query string parameter.

protected string GetImageUrl()
          return String.Format(<a href="%22http://localhost:1404/WhiteImage.png?id={0}"">http://localhost:1404/WhiteImage.png?id={0}</a>,

And here is the ASPX code that uses the GetImageUrl method.

<form id="form1" runat="server">

   This is some email that I am reading. This is a test email.

   <img src='<%= GetImageUrl() %>' />


The HTML produced by the above code will look something like this:


Our next task is to handle the request from our WhiteImage.png image. The best way to handle this request is to create a custom HttpHandler.

Creating EmailViewedNotificationHandler

The purpose of EmailViewedNotificationHandler is to intercept the request for WhiteImage.png and then update a field in the database and finally render the image to the browser. The ProcessRequest method is where the magic happens. Let's take a look at the ProcessRequest implementation.

public void ProcessRequest(HttpContext context)
           string id = context.Request.QueryString["id"] as String;

           if (String.IsNullOrEmpty(id)) return;

           Guid guid = new Guid(id);


           // render the image!
           MemoryStream ms = new MemoryStream();
           Bitmap bitMap = new Bitmap(context.Request.PhysicalPath);
           bitMap.Save(ms, ImageFormat.Png);

           byte[] buffer = ms.ToArray();

           context.Response.ContentType = "image/png";

The ProcessRequest method first extracts the query string and gets the Guid. Then the EmailNotificationService class is used to update the Guid status in the database. This class is not implemented in the article. Finally, the image is written to the MemoryStream which is outputted to the client.


Adding HttpHandler Configuration in Web.Config

In order to work with the new HttpHandler you will need to register it in the Web.config file. Take a look at the following code that does this:

            <remove verb="*" path="*.asmx"/>

      <add verb="*" path="WhiteImage.png"


You might also want to adjust your FileMappings in IIS to work with the new HttpHandler.


In this article we learned how to create a simple HttpHandler that will notify the sender when the email is opened. This can be useful in scenarios where viewing of an email is absolutely necessary.

NOTE: If the client has an image blocking filter active then the image will never be downloaded and the above code will not work.

UPDATE: You can also use the .GIF transparent images


  1. Sending Emails in ASP.NET 2.0
  2. Sending Emails in ASP.NET


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Web Developer
United States United States
I am the founder of knowledge base website, HighOnCoding, GridViewGuy, and

HighOnCoding is a website which will get you high legally with useful information. There are tons of articles, videos and podcasts hosted on HighOnCoding.

My Blog:


Buy my iPhone app ABC Pop

You may also be interested in...

Comments and Discussions

RantMy vote of 1 Pin
Jonathan C Dickinson20-Jan-09 20:33
memberJonathan C Dickinson20-Jan-09 20:33 
GeneralRe: My vote of 1 Pin
Jonathan C Dickinson20-Jan-09 20:39
memberJonathan C Dickinson20-Jan-09 20:39 
GeneralRe: My vote of 1 Pin
SamNaseri5-Dec-11 19:32
memberSamNaseri5-Dec-11 19:32 
GeneralInteresting introduction Pin
Chiew Heng Wah19-Jan-09 19:55
memberChiew Heng Wah19-Jan-09 19:55 
GeneralMy vote of 1 Pin
Matt Sollars19-Jan-09 7:04
memberMatt Sollars19-Jan-09 7:04 
GeneralIn most cases this will work Pin
defwebserver19-Jan-09 3:53
memberdefwebserver19-Jan-09 3:53 
GeneralRe: In most cases this will work Pin
azamsharp19-Jan-09 4:28
memberazamsharp19-Jan-09 4:28 
GeneralMy vote of 1 Pin
Wolfgang Schober19-Jan-09 1:48
memberWolfgang Schober19-Jan-09 1:48 
GeneralMy vote of 1 Pin
Michael B. Hansen16-Jan-09 7:37
memberMichael B. Hansen16-Jan-09 7:37 
Oldest spammer trick in the book
GeneralRe: My vote of 1 Pin
azamsharp16-Jan-09 9:34
memberazamsharp16-Jan-09 9:34 
RantRe: My vote of 1 Pin
Jonathan C Dickinson20-Jan-09 20:34
memberJonathan C Dickinson20-Jan-09 20:34 
Generalgood idea Pin
Haozes15-Jan-09 22:04
memberHaozes15-Jan-09 22:04 
GeneralMy vote of 1 Pin
J a a n s15-Jan-09 21:25
professionalJ a a n s15-Jan-09 21:25 
GeneralRe: My vote of 1 Pin
azamsharp16-Jan-09 3:11
memberazamsharp16-Jan-09 3:11 
GeneralMy vote of 1 Pin
Rogic15-Jan-09 15:15
memberRogic15-Jan-09 15:15 
Jokeimprove :) Pin
teleprobst-ober15-Jan-09 11:24
memberteleprobst-ober15-Jan-09 11:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web04 | 2.8.181215.1 | Last Updated 15 Jan 2009
Article Copyright 2009 by azamsharp
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid