423,688 Members | 1,894 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,688 IT Pros & Developers. It's quick & easy.

Email Tracking using asp.net

P: 24
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
Expand|Select|Wrap|Line Numbers
  1.         try
  2.         {
  3.  
  4.             string emailTemplateBody = "Hy this is test mail";
  5.                        emailTemplateBody += "<tr><img src=''http://localhost:52583/HttpModule_using_beacon_images/images/<keyvalue>.aspx''  style=''opacity:0.0; filter:alpha(opacity=0);'' /></tr>";
  6.  
  7.  
  8.  
  9.             string templateName = txtTemplateName.Text;
  10.  
  11.                         string toEmail = mymailaddress
  12.  
  13.             //// Get unique Key after registring mail to be sent
  14.             string key = bl_email_calls.RegisterSystemEmailAudit("1", templateName, DateTime.Now);
  15.             emailTemplateBody = emailTemplateBody.Replace("<keyvalue>", key);
  16.             //// sending e-mail
  17.             bl_email_calls.SendMailMessage(toEmail, templateName, emailTemplateBody, key);
  18.             using (var cn = new SqlConnection(ConfigurationManager.ConnectionStrings["webConnectionString"].ToString()))
  19.             {
  20.                //code to insert record in database;            }
  21.             Response.Write("Mail sent");
  22.             // return false;
  23.         }
  24.         catch (Exception ex)
  25.         {
  26.  
  27.             throw;
  28.         }
  29.  
  30.  
Here is my HTTP module i have used from http://www.aspnetemail.com/samples/e...r/default.aspx[^]
Expand|Select|Wrap|Line Numbers
  1. public class HttpModuleClass : IHttpModule
  2.     {
  3.         //public event EventHandler BeginRequest;
  4.  
  5.         public void Dispose()
  6.         {
  7.  
  8.         }
  9.  
  10.         /// <summary>
  11.         /// public varibles
  12.         /// </summary>
  13.         string footerFile = "~/images/footer.png";
  14.         //string footerFile = "~/images/ajax-loader.gif";
  15.         Email_Calls bl_email_calls = new Email_Calls();
  16.  
  17.         /// <summary>
  18.         /// Init methoed
  19.         /// </summary>
  20.         /// <param name="context"></param>
  21.         public void Init(HttpApplication context)
  22.         {
  23.             context.BeginRequest += new System.EventHandler(GetImage_BeginRequest);
  24.         }
  25.  
  26.         /// <summary>
  27.         /// handles requests made to server and call update email read time
  28.         /// </summary>
  29.         /// <param name="sender"></param>
  30.         /// <param name="args"></param>
  31.         public void GetImage_BeginRequest(object sender, System.EventArgs args)
  32.         {
  33.             //cast the sender to a HttpApplication object
  34.             System.Web.HttpApplication application = (System.Web.HttpApplication)sender;
  35.  
  36.             string url = application.Request.Path; //get the url path
  37.             //string pattern = @"/HttpModule/images/(?<key>.*)\.aspx";
  38.             //string pattern = @"/HttpModule_using_beacon_images/images/(?<key>.*)\.aspx";
  39.  
  40.             string pattern = @"/HttpModule_using_beacon_images/images/(?<key>.*)\.aspx";
  41.             //string pattern = @"~/images/(?<key>.*)\.aspx";
  42.             //create the regex to match for beacon images
  43.             Regex r = new Regex(pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
  44.             if (r.IsMatch(url))
  45.             {
  46.                 MatchCollection mc = r.Matches(url);
  47.                 if ((mc != null) && (mc.Count > 0))
  48.                 {
  49.                     string key = (mc[0].Groups["key"].Value);
  50.                     bl_email_calls.UpdateSystemEmailAuditReadDate(key);
  51.  
  52.                 }
  53.  
  54.                 //now send the REAL image to the client
  55.                 //application.Response.ContentType = "image/gif";
  56.                 application.Response.ContentType = "image/png";
  57.  
  58.                 application.Response.WriteFile(application.Request.MapPath(footerFile));
  59.  
  60.                 //end the response
  61.                 application.Response.End();
  62.             }
  63.         }
  64.     }
  65. Please help
  66.  
Jun 11 '12 #1

✓ answered by Maraj

I got it.I was making some little mistakes.Actually 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.

Share this Question
Share on Google+
6 Replies


P: 24
I got it.I was making some little mistakes.Actually 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.
Jun 12 '12 #2

Frinavale
Expert Mod 5K+
P: 9,731
I'm glad you solved your problem!

Thanks for sharing your solution

-Frinny
Jun 18 '12 #3

P: 1
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....
Jan 10 '13 #4

Frinavale
Expert Mod 5K+
P: 9,731
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
Jan 10 '13 #5

P: 5
Kindly send me full code for this. Thanks
2 Weeks Ago #6

P: 5
actually I need code of Email_Calls()
2 Weeks Ago #7

Post your reply

Sign in to post your reply or Sign up for a free account.