Monday, May 6, 2013

Email Tracking using ASP.NET


We have many more ways to advertise a business or a product. But one of main way is Email through advertisement.
However, how many users opened their advertisement emails or newsletter emails. So we needs the opened email counts. In this article describes, how can we count the opened email?
   public void SendMail()
   {
       string toEmail = "abiice.1987@gmail.com";
       System.Net.Mail.MailMessage eMail = new System.Net.Mail.MailMessage();
       eMail.From = new System.Net.Mail.MailAddress("test@test.com");
       eMail.To.Add(toEmail);
       eMail.Subject = "test track";
       eMail.IsBodyHtml = true;
eMail.Body = "test body<IMG height=1       src='http://localhost:12207/EmailTrack/emailtrack.aspx?emailsent='"+toEmail+"'   width=1>";
       System.Net.Mail.SmtpClient SMTP = new System.Net.Mail.SmtpClient();
       SMTP.Send(eMail);
       eMail.Dispose();

    }

The above code describes the, how to send an email through Asp.Net. We needs Track the email so we could append an image inside the email body and we add a query string value to the SRC attribute. The query string helps to identify the user.
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack == false)
        {
            if (Request.Params["emailsent"] != null)
            {
            }
        }
    }
Then user open an email the request comes to web server and we get a querystring values and maintain the counts using database


1 comment: