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))
{
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"]);
}
else
{
if (Request.QueryString["emailId"] != null)
{
lblid.Text = Convert.ToString(Request.QueryString["emailId"]);
}
string str = "<script>alert('empty')</script>";
Page.RegisterStartupScript("popup", str);
}
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)
{
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
user2977985
source
share