0
我創建了一個密碼恢復頁面,該頁面向用戶發送一封電子郵件,其中包含指向另一個頁面的鏈接,他可以在其中重置密碼。這裏是我的代碼文件..發送本地主機鏈接到ASP中的電子郵件?
protected void btnSubmit_Click(object sender, EventArgs e)
{
try
{
DataSet ds = new DataSet();
using (SqlConnection con = new SqlConnection("Data Source=DBS_WINDOWS7;Initial Catalog=LMS;Integrated Security=True"))
{
con.Open();
SqlCommand cmd = new SqlCommand("SELECT AccountID, Password FROM tblAccount Where Email= '" + txtEmail2.Text.Trim() + "'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
con.Close();
}
if (ds.Tables[0].Rows.Count > 0)
{
MailMessage Msg = new MailMessage();
// Sender e-mail address.
Msg.From = new MailAddress(txtEmail2.Text);
// Recipient e-mail address.
Msg.To.Add(txtEmail2.Text);
Msg.Subject = "Your Password Details";
Msg.Body = HttpContext.Current.Request.Url.Host + @"Login.aspx?id=id";
Msg.IsBodyHtml = true;
// your remote SMTP server IP.
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new System.Net.NetworkCredential("[email protected]", "dummypassword");
smtp.EnableSsl = true;
smtp.Send(Msg);
//Msg = null;
lbltxt.Text = "<i class='icon-check-sign'></i> We have sent your password. Go check it out!";
lbltxt.CssClass = "alert alert-success";
// Clear the textbox valuess
txtEmail.Text = "";
txtEmail2.Text = "";
}
else
{
lbltxt.CssClass = "alert alert-error";
lbltxt.Text = "<i class='icon-question-sign'></i> Something went wrong. Are you sure that's your email with us?";
}
}
catch (Exception ex)
{
Console.WriteLine("{0} Exception caught.", ex);
}
}
電子郵件發送作品完美,但我想顯示的鏈接無法點擊和@"Login.aspx?id=id";
行代碼直接印在發送的電子郵件。
該項目託管在localhost的方式。
所以我的問題是: 爲什麼這段代碼不會創建一個可點擊的鏈接到用戶應該重置密碼的頁面?有人可以分享他們的想法嗎?
任何幫助將不勝感激!
你缺少把登錄URL的鏈接裏面,例如:Login –
^我嘗試添加一個'Links'但我的瀏覽器將我重定向到'http://www.login.aspx/?id = id',而不是他應該定向的頁面。有任何想法嗎?謝謝你的幫助! – Saudate