Introduction:
Email is very important in many web application and web technologies. Sending email is easy but tracking email status i.e. email is delivered to recipient or not it’s a difficult part. Email tracking is useful when the sender wants to know if the recipient actually received the email.
We can track email status by implementing HttpModule. In this method image is wrapped with HTML composed email. This HttpModule will intercept a request to embedded image. This image is act as an email key which is unique for each email. That image has SRC attribute which is pointing to another external file, it will look like below
protected void btnSendMail_Click(object sender, EventArgs e) { // a unique-id to attach with the mail var messageId = Guid.NewGuid(); // the server get request from the image and process it var externalfile= "http://www.yoursite.com//images//MyDemo.aspxf?key=textkey"; // the image tag with "src" pointing to the external resource // passing necessary parameter and unique-id in the query-string. var imgTag = string.Format(@" style=""width: 0px; height: 0px; border:0px;"" />", externalfile, messageId); System.Net.Mail.MailMessage oMail = new System.Net.Mail.MailMessage("sender@mainhost.com", "receiver@subhost.com") oMail.Subject = "Email delivery using HttpModule"; oMail.Body = "An image is attached with this email, please enable the images on reading the email so we will know you got the email."; //append the image tag at the end of the body. oMail.Body += imgTag; oMail.IsBodyHtml = true; SmtpClient sm = new SmtpClient("smtp.gmail.com"); sm.Port = 587; sm.DeliveryMethod = SmtpDeliveryMethod.Network; sm.Credentials = new System.Net.NetworkCredential("userid", "password"); sm.EnableSsl = true; }
When receiver try to read email then GetImage() is called. Inside this method it check the path and run the expression http://www.yoursite.com//images//MyDemo.aspx ,it will return email key. That key is then passed to the the GetKey method ,here we can save this key into database. Using this key later we can determine which email were read and it will return Image as acknowledgement.
Once we done with above HttpModule we have to deploy it, for that some entries need to do in web.config file as below:
<system.web> <httpModules> <add type="LoadImage.Request1,LoadImage" name="LoadImage" /> </httpModules> </system.web>
Limitation:
1. This mechanism will not work for gmail.