protected void Button1_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(tbxMail.Text)) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('متنی وارد نشده است ! ');", true); return; } if (Session["ImgValue"].ToString() == txtImage.Value.ToUpper()) { } else { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('کد وارد شده صحیح نمی باشد ! ');", true); txtImage.Value = ""; Session.Remove("ImgValue"); FillImageText(); return; } /////////////////////////////////////////////////////////////////////////////////// if (rdiEmployees.Checked == true) { EmployeesRepository r = new EmployeesRepository(); Employee emp = r.ChekEmployee(tbxMail.Text); if (emp == null) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('چنین کاربری وجود ندارد ! ');", true); txtImage.Value = ""; Session.Remove("ImgValue"); FillImageText(); return; } else { string smtpAddress = "smtp.gmail.com"; int portNumber = 587; bool enableSSL = true; string emailFrom = "*****@*****.**"; string password = "******"; string emailTo = emp.Email; string subject = "فراموشی رمز"; string body = "<p style='direction: rtl; text - align:right'><p><span style='font-size:18px'><strong>کاربر محترم سلام.</strong></span></p><p>این پیام شامل رمز ورود شما میباشد و به این دلیل برای شما ارسال شده که شخصی ایمیل شما را در بخش فراموشی رمز عبور وارد کرده است.</p><p>اگر این شخص شما نبوده اید این پیام را نادیده بگیرید،در غیر این صورت میتوانید با اطلاعات زیر وارد شوید :</p><p>نام کاربری :" " + emp.UserName + " " </p><p>رمزعبور :" " + emp.Password + " " </p><p style='text-align:center'>با تشکر</p><p style='text-align:center'>تیم پشتیبانی <a href='http://*****:*****@gmail.com"; string password = "******"; string emailTo = user.Email; string subject = "فراموشی رمز"; string body = "<p style='direction: rtl; text - align:right'><p><span style='font-size:18px'><strong>کاربر محترم سلام.</strong></span></p><p>این پیام شامل رمز ورود شما میباشد و به این دلیل برای شما ارسال شده که شخصی ایمیل شما را در بخش فراموشی رمز عبور وارد کرده است.</p><p>اگر این شخص شما نبوده اید این پیام را نادیده بگیرید،در غیر این صورت میتوانید با اطلاعات زیر وارد شوید :</p><p>نام کاربری :"" + user.UserName + ""</p><p>رمزعبور :"" + user.Password + ""</p><p style='text-align:center'>با تشکر</p><p style='text-align:center'>تیم پشتیبانی <a href='http://localhost:6421'>وبسایت</a></p></p>"; using (MailMessage mail = new MailMessage()) { bool result = true; mail.From = new MailAddress(emailFrom); mail.To.Add(emailTo); mail.Subject = subject; mail.Body = body; mail.IsBodyHtml = true; using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber)) { smtp.UseDefaultCredentials = false; smtp.Credentials = new NetworkCredential(emailFrom, password); smtp.EnableSsl = enableSSL; try { smtp.Send(mail); } catch (Exception) { result = false; } } if (result) { Response.Redirect("/Login"); } else { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('مشکلی در زمان ارسال به وجود امد،دوباره سعی کنید ! ');", true); } } } } }