Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 20th, 2012  |  syntax: None  |  size: 3.18 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Email Tracking using asp.net
  2. try
  3.         {
  4.  
  5.         string emailTemplateBody = "Hy this is test mail";
  6.         emailTemplateBody += "<tr><img src=''http://localhost:52583/HttpModule_using_beacon_images/images/<keyvalue>.aspx''  style=''opacity:0.0; filter:alpha(opacity=0);'' /></tr>";
  7.  
  8.  
  9.  
  10.         string templateName = txtTemplateName.Text;
  11.  
  12.                     string toEmail = mymailaddress
  13.  
  14.         //// Get unique Key after registring mail to be sent
  15.         string key = bl_email_calls.RegisterSystemEmailAudit("1", templateName, DateTime.Now);
  16.         emailTemplateBody = emailTemplateBody.Replace("<keyvalue>", key);
  17.         //// sending e-mail
  18.         bl_email_calls.SendMailMessage(toEmail, templateName, emailTemplateBody, key);
  19.         using (var cn = new SqlConnection(ConfigurationManager.ConnectionStrings["webConnectionString"].ToString()))
  20.         {
  21.            //code to insert record in database;            }
  22.         Response.Write("Mail sent");
  23.         // return false;
  24.     }
  25.     catch (Exception ex)
  26.     {
  27.  
  28.         throw;
  29.     }
  30.        
  31. public class HttpModuleClass : IHttpModule
  32. {
  33.     //public event EventHandler BeginRequest;
  34.  
  35.     public void Dispose()
  36.     {
  37.  
  38.     }
  39.  
  40.     /// <summary>
  41.     /// public varibles
  42.     /// </summary>
  43.     string footerFile = "~/images/footer.png";
  44.     //string footerFile = "~/images/ajax-loader.gif";
  45.     Email_Calls bl_email_calls = new Email_Calls();
  46.  
  47.     /// <summary>
  48.     /// Init methoed
  49.     /// </summary>
  50.     /// <param name="context"></param>
  51.     public void Init(HttpApplication context)
  52.     {
  53.         context.BeginRequest += new System.EventHandler(GetImage_BeginRequest);
  54.     }
  55.  
  56.     /// <summary>
  57.     /// handles requests made to server and call update email read time
  58.     /// </summary>
  59.     /// <param name="sender"></param>
  60.     /// <param name="args"></param>
  61.     public void GetImage_BeginRequest(object sender, System.EventArgs args)
  62.     {
  63.         //cast the sender to a HttpApplication object
  64.         System.Web.HttpApplication application = (System.Web.HttpApplication)sender;
  65.  
  66.         string url = application.Request.Path; //get the url path
  67.         //string pattern = @"/HttpModule/images/(?<key>.*).aspx";
  68.         //string pattern = @"/HttpModule_using_beacon_images/images/(?<key>.*).aspx";
  69.  
  70.         string pattern = @"/HttpModule_using_beacon_images/images/(?<key>.*).aspx";
  71.         //string pattern = @"~/images/(?<key>.*).aspx";
  72.         //create the regex to match for beacon images
  73.         Regex r = new Regex(pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
  74.         if (r.IsMatch(url))
  75.         {
  76.             MatchCollection mc = r.Matches(url);
  77.             if ((mc != null) && (mc.Count > 0))
  78.             {
  79.                 string key = (mc[0].Groups["key"].Value);
  80.                 bl_email_calls.UpdateSystemEmailAuditReadDate(key);
  81.  
  82.             }
  83.  
  84.             //now send the REAL image to the client
  85.             //application.Response.ContentType = "image/gif";
  86.             application.Response.ContentType = "image/png";
  87.  
  88.             application.Response.WriteFile(application.Request.MapPath(footerFile));
  89.  
  90.             //end the response
  91.             application.Response.End();
  92.         }
  93.     }
  94. }
  95.        
  96. mail.Headers.Add("Disposition-Notification-To", "<mail@yahoo.com>");