Email Tracking using asp.net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Maraj
    New Member
    • Nov 2011
    • 24

    Email Tracking using asp.net

    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
    Code:
            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/e...r/default.aspx[^]
    Code:
    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
    Last edited by jhardman; Jun 11 '12, 12:10 PM. Reason: Accidentally posted in the classic asp forum. Moved to asp.net
  • Maraj
    New Member
    • Nov 2011
    • 24

    #2
    I got it.I was making some little mistakes.Actual ly i was saving the email body in database so i had to use '' instead of ' and that was making all the trouble.When is removed '' it worked fine.

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      I'm glad you solved your problem!

      Thanks for sharing your solution

      -Frinny

      Comment

      • Nagendrach
        New Member
        • Jan 2013
        • 1

        #4
        please any one can send me solution in asp.net 10.0 version for this coding. my email addrs:- [email id removed].
        i didn't understand how can i do this... please help me..

        Thanks in advance....
        Last edited by Meetee; Jan 10 '13, 11:52 AM. Reason: Do not post email id

        Comment

        • Frinavale
          Recognized Expert Expert
          • Oct 2006
          • 9749

          #5
          Check out this quick reference on how to send an email using .net. It has details on what you need to do using the .NET Framework version 1.1.

          -Frinny

          Comment

          • Pkaursikhni
            New Member
            • Apr 2010
            • 5

            #6
            Kindly send me full code for this. Thanks

            Comment

            • Pkaursikhni
              New Member
              • Apr 2010
              • 5

              #7
              actually I need code of Email_Calls()

              Comment

              Working...