Click here to Skip to main content
15,901,283 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to track users who have read my mails.I am doing this but it's not working
I am sending mails to myself in outlook.
Here is my code which sends mails
C#
try
{

    string emailTemplateBody = "Hy this is test mail";
               emailTemplateBody += "<tr><img src=''http://localhost:52583/HttpModule_using_beacon_images/images/<keyvalue>.aspx''  style=''opacity:0.0; filter:alpha(opacity=0);'' /></tr>";



    string templateName = txtTemplateName.Text;

                string toEmail = mymailaddress

    //// Get unique Key after registring mail to be sent
    string key = bl_email_calls.RegisterSystemEmailAudit("1", templateName, DateTime.Now);
    emailTemplateBody = emailTemplateBody.Replace("<keyvalue>", key);
    //// sending e-mail
    bl_email_calls.SendMailMessage(toEmail, templateName, emailTemplateBody, key);
    using (var cn = new SqlConnection(ConfigurationManager.ConnectionStrings["webConnectionString"].ToString()))
    {
       //code to insert record in database;            }
    Response.Write("Mail sent");
    // return false;
}
catch (Exception ex)
{

    throw;
}


Here is my HTTP module i have used from http://www.aspnetemail.com/samples/emailtracker/default.aspx[^]
C#
public class HttpModuleClass : IHttpModule
    {
        //public event EventHandler BeginRequest;

        public void Dispose()
        {

        }

        /// <summary>
        /// public varibles
        /// </summary>
        string footerFile = "~/images/footer.png";
        //string footerFile = "~/images/ajax-loader.gif";
        Email_Calls bl_email_calls = new Email_Calls();

        /// <summary>
        /// Init methoed
        /// </summary>
        /// <param name="context"></param>
        public void Init(HttpApplication context)
        {
            context.BeginRequest += new System.EventHandler(GetImage_BeginRequest);
        }

        /// <summary>
        /// handles requests made to server and call update email read time
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        public void GetImage_BeginRequest(object sender, System.EventArgs args)
        {
            //cast the sender to a HttpApplication object
            System.Web.HttpApplication application = (System.Web.HttpApplication)sender;

            string url = application.Request.Path; //get the url path
            //string pattern = @"/HttpModule/images/(?<key>.*)\.aspx";
            //string pattern = @"/HttpModule_using_beacon_images/images/(?<key>.*)\.aspx";

            string pattern = @"/HttpModule_using_beacon_images/images/(?<key>.*)\.aspx";
            //string pattern = @"~/images/(?<key>.*)\.aspx";
            //create the regex to match for beacon images
            Regex r = new Regex(pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
            if (r.IsMatch(url))
            {
                MatchCollection mc = r.Matches(url);
                if ((mc != null) && (mc.Count > 0))
                {
                    string key = (mc[0].Groups["key"].Value);
                    bl_email_calls.UpdateSystemEmailAuditReadDate(key);

                }

                //now send the REAL image to the client
                //application.Response.ContentType = "image/gif";
                application.Response.ContentType = "image/png";

                application.Response.WriteFile(application.Request.MapPath(footerFile));

                //end the response
                application.Response.End();
            }
        }
    }

Please help
Posted

And what is not working exactly? Images are not downloaded by default in Outlook. I am afraid this will not work as you expect due to security reasons.
 
Share this answer
 
Comments
MairajAhmed 11-Jun-12 7:59am    
When i open email it's not working and value is not saved in db from this call
bl_email_calls.UpdateSystemEmailAuditReadDate(key);
Zoltán Zörgő 11-Jun-12 8:33am    
That is what I am expecting. Have you looked with a network sniffer (Microsoft Network Monitor or WhireShark) if the http get to the image url is even fetched? Try it and you will see that as I mentioned, the image is not fetched, thus there is no client request to your serverside code. You have to explicitly enable in outlook to fetch images from specified source: this is why it wont work in a general case. However it can be made to work in a corporate intranet.
MairajAhmed 11-Jun-12 8:50am    
when i type url in address bar it works and goes to that call
Zoltán Zörgő 11-Jun-12 9:02am    
I can only repeat myself: Outlook won't call this url for you, because of security considerations.
MairajAhmed 11-Jun-12 9:10am    
so what should i do now?
Hi,
Go through the link below-
Email tracking[^]
 
Share this answer
 
Comments
Zoltán Zörgő 11-Jun-12 8:38am    
I suppose he already did that; see his link in the middle of the post. It is the same as yours :)

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900