Tracking whether the sent mail is read or not.

I searched a lot of articles and found the code, but it does not work for me.

Code of my 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;
}

My index.aspx page looks like:

<body>
<form id="form1" runat="server">
<asp:Label ID="lblid" runat="server" Text=""></asp:Label>   
</form>
</body>

I used to send email to my own Gmail id from my aspx page, for example:

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);

Here, the mail is successfully sent to my Gmail account at mitesh@gmail.comid, but when I open this letter from my account, I do not receive a value Request.QueryString["emailId"]as 1 for myindex.aspx

+4
source share
1 answer

See answers to the following questions:

Is there a way to track if an email has been opened?

Bulk Email Tracking

:

. - , , , .

, , , ( ). , - , ​​.

+1

Source: https://habr.com/ru/post/1527437/


All Articles