我搜索了很多文章并找到了一些代码,但它对我不起作用.
我的index.aspx.cs页面代码是:
protected void Page_Load(object sender,EventArgs e) { if (checkIfRequested(this.Context.Request)) { //receiver had already requested the image,hence send back a not modified result Response.StatusCode = 304; Response.SuppressContent = true; } else { int emailId = 0; if (!string.IsNullOrEmpty(Request.QueryString["emailId"]) && int.TryParse(Request.QueryString["emailId"],out emailId)) { Session["image"] = Request.QueryString["emailId"]; lblid.Text = Convert.ToString(Session["image"]); //The email with emailId has been opened,so log that in database } else { if (Request.QueryString["emailId"] != null) { lblid.Text = Convert.ToString(Request.QueryString["emailId"]); } string str = "<script>alert('empty')</script>"; Page.RegisterStartupScript("popup",str); } //Send the single pixel gif image as response byte[] imgbytes = Convert.FromBase64String("R0lGODlhAQABAIAAANvf7wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="); Response.ContentType = "image/gif"; Response.AppendHeader("Content-Length",imgbytes.Length.ToString()); Response.Cache.SetLastModified(DateTime.Now); Response.Cache.SetCacheability(HttpCacheability.Public); Response.BinaryWrite(imgbytes); } } private bool checkIfRequested(HttpRequest req) { // check if-modified-since header to check if receiver has already requested the image in last 24 hours return req.Headers["If-Modified-Since"] == null ? false : DateTime.Parse(req.Headers["If-Modified-Since"]).AddHours(24) >= DateTime.Now; }
我的index.aspx页面如下:
<body> <form id="form1" runat="server"> <asp:Label ID="lblid" runat="server" Text=""></asp:Label> </form> </body>
我曾经从我的aspx页面发送电子邮件到我自己的Gmail ID,如:
String MailContent = ""; MailContent += "<img src='http://WWW.mywebsitename.com/index.aspx?emailId=1' width='1' height='1' /> client = new SmtpClient(); client.UseDefaultCredentials = false; client.Credentials = new System.Net.NetworkCredential("Myemailidofhmail","mypassword"); client.Port = 25; client.Host = "smtp.gmail.com"; client.EnableSsl = true; mailto = "mitesh@gmail.com"; message = MailContent.ToString(); msg = new System.Net.Mail.MailMessage(); msg.To.Add(mailto);
这里的邮件已成功发送到我的Gmail帐户mitesh@gmail.com id,但是当我从我的帐户打开该电子邮件时,我没有将Request.QueryString [“emailId”]值作为1传递给我的index.aspx
解决方法
请查看以下问题的答案:
Is there any way to track whether an email has been opened?
引用第一个问题的答案:
Mail clients block pretty much all of these kinds of attempts. The
best idea is to give them an image that they would want to see if they
read the message,and therefore they choose to display images in their
mail client.
所以,是的,这几乎是最好的建议,即使这样,如果电子邮件客户端缓存您的图像(尽管它仍然能够记录第一次下载),它可能无法正常工作.没有万无一失的方法来实际验证某人是否阅读了您的电子邮件,除非您可以通过电子邮件中的链接访问您的网站.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。