我搜索了很多文章并找到了一些代码,但它对我不起作用。
我的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);
此处邮件已成功发送到mitesh@gmail.com
个ID上的我的Gmail帐户,但是当我从我的帐户中打开该电子邮件时,我的Request.QueryString["emailId"]
<1的值不是index.aspx
/ p>
答案 0 :(得分:1)
请参阅这些问题的答案:
Is there any way to track whether an email has been opened?
引用第一个问题的答案:
邮件客户端阻止了所有这些尝试。该 最好的想法是给他们一个他们希望看到的图像 阅读消息,因此他们选择在他们的图像中显示图像 邮件客户端。
所以,是的,这几乎是最好的建议,即使这样,如果电子邮件客户端缓存你的图像它可能也不会很好(尽管它应该仍然可以记录第一次下载)。没有万无一失的方法来实际验证某人是否阅读了您的电子邮件,除非您可以通过电子邮件中的链接访问您的网站。