Description:-
In
this Example we Explain that How to Send Password to user Email when user click
on Forgot password and enter his/her Email.
Here we can not send other password or autogenerate
password. We simply send current password of the user to his/her email.
To auto Generate password please click Here How to Auto Generate Unique Password in Asp.Net
This Example is very useful when user Forgot his
password and we can easily give his password by sendin in Email.
We all know that in Corporate world today this
Forgot password Facility available in Every place.so you can easily send Forgot
password to the user Email or user mobile number by sending SMS to user in your mobile.
To send SMS in Asp.Net to any User then click Here Send SMS or message in Asp.net
To send SMS in Asp.Net to any User then click Here Send SMS or message in Asp.net
First to do this You have to create a one table like
To Send Email in Asp.Net click Here Send Email to Other user in ASP.net
To send Email with Attechment File click Here Send Email with Atteched File in Asp.Net
To Import Gmail Contact in Asp.Net click here Import contact from Gmail in asp.net
To send Email to Multiple User at a time based on checkbox selection click here Send Email to Multiple User in Asp.net
To Send Forgot to an Email in Asp.Net click here Send Forgot Password to user's Email
forgotpassword.aspx:-
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="forgotpassword.aspx.cs" Inherits="forgotpassword" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table cellspacing="2" cellpadding="2" border="0">
<tr><td></td><td><b>Forgot
Password Example</b></td></tr>
<tr><td><b>Enter
Your Email:</b></td><td><asp:TextBox ID="txtEmail" runat="server" /></td></tr>
<tr><td></td><td><asp:button ID="btnSubmit" Text="Submit" runat="server" onclick="btnSubmit_Click" CssClass="Button"/></td></tr>
<tr><td colspan="2" style=" color:red"><asp:Label ID="lbltxt" runat="server"/></td></tr>
</table>
</div>
</form>
</body>
</html>
forgotpassword.aspx.cs:-
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Net.Mail;
using
System.Data.SqlClient;
using
System.Data;
public partial class forgotpassword :
System.Web.UI.Page
{
protected void
Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object
sender, EventArgs e)
{
try
{
DataSet ds
= new DataSet();
using (SqlConnection
con = new SqlConnection("Data
Source=SQLDB;Initial Catalog=Demo;User ID=Demoh;Password=Demo1@"))
{
con.Open();
SqlCommand
cmd = new SqlCommand("SELECT
username,password FROM Login Where email= '" +
txtEmail.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(txtEmail.Text);
// Recipient e-mail address.
Msg.To.Add(txtEmail.Text);
Msg.Subject = "Your
Password Details";
Msg.Body = "Hi,
<br/>Please check your Login Detailss<br/><br/>Your Username:
" + ds.Tables[0].Rows[0]["username"] +
"<br/><br/>Your Password: " +
ds.Tables[0].Rows[0]["password"] +
"<br/><br/>";
Msg.IsBodyHtml = true;
// your remote SMTP server
IP.
SmtpClient
smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.Credentials = new
System.Net.NetworkCredential ("your
email@gmail.com", "password");
smtp.EnableSsl = true;
smtp.Send(Msg);
//Msg = null;
lbltxt.Text = "Your
Password Details Sent to your mail";
// Clear the textbox valuess
txtEmail.Text = "";
}
else
{
lbltxt.Text = "The
Email you entered not exists.";
}
}
catch (Exception
ex)
{
Console.WriteLine("{0}
Exception caught.", ex);
}
}
}
error showing
ReplyDeleteThe SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at
This comment has been removed by the author.
ReplyDeleteFirst Configure the smtp server like using this link http://aspsolutionkirit.blogspot.in/2013/07/how-to-send-mail-to-other-user-in-aspnet.html
Delete