How to send Forget password from asp.net website Free

By
Hi, Friends today i am going to make a Forget password Form application,so that any body can get your Forget password on your registered mail from ASP.NET website free. Previously i have made Registration and Login page Application,You can attach this Forget password page in this application.Here I have used gmail SMTP server for sending the User Name and respective password value to the registered email address.You can use your own server instead of gmail server for this purpose.It is full secure because you are sending the mail through gmail SMTP server.But for own Hosting you can use your SMTP server.The Students who are making any project they can use this service free because server space is more costly.   
There are some steps to implement this concept in your ASP.NET website.
Step 1:- First open your visual studio --> File  --> New  -->website -->ASP.NET EMPTY WEBSITE  -->OK -->Now open your Solution Explorer -->Add a web Form  -->Drag and Drop Label,Text Box and Button controls on the form as shown below:- 

forget-form

Step 2:- Now Add a Database.mdf file for stored the registration value in the website  -->Create a emp table -->register some person also as shown below.
emp-table

Note:- If you are facing any problem to create .mdf file on website,please read below link:-
Step 3:- Now Double click on Submit button--> and write the following codes.
using System;
using System.Data.SqlClient;
using System.Data;
using System.Net.Mail;
using System.Net;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
     SqlConnection con = new SqlConnection(@"Data Source=.\;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True;");
     con.Open();
     SqlCommand cmd = new SqlCommand("SELECT username,password FROM emp Where email= '" +TextBox1.Text + "'", con);
     SqlDataAdapter da = new SqlDataAdapter(cmd);
     DataSet ds = new DataSet();
     da.Fill(ds);
     con.Close();
     if (ds.Tables[0].Rows.Count > 0)
     {
         MailMessage email = new MailMessage();
         email.From = new MailAddress(TextBox1.Text); //Enter sender email address
         email.To.Add(TextBox1.Text); //Destination Recipient e-mail address.
         email.Subject = "Your Forrget Password:";//Subject for your request
         email.Body = "Hi,<br/>Your Username is: " + ds.Tables[0].Rows[0]["username"] + "<br/><br/>Your Password is: " + ds.Tables[0].Rows[0]["Password"] + "<br/>";
         email.IsBodyHtml = true;
         //SMTP SERVER DETAILS
         SmtpClient smtpc = new SmtpClient("smtp.gmail.com");
         smtpc.Port = 587;
         smtpc.UseDefaultCredentials = false;
         smtpc.EnableSsl = true;
         Label1.Text = "aryas@gmail.com"; //<--Enter your gmail id here
         Label2.Text = "94804";//<--Enter gmail password here
         //Label3.Text = "msdotnet website"; //Subject for your website
         //Label4.Text = "webcome to http://msdotnet.co.in. please share this website to your friends"; //Message body
         smtpc.Credentials = new NetworkCredential(Label1.Text, Label2.Text);
         smtpc.Send(email);
         Label2.Text = "Your password has been sent to your email address";
     }
         else
         {
         Label3.Text="This email address is not exist in our Database try again";
         }
     }
     
    }

Step 4:- Now Run the application(press F5)-->Now Enter your registered Email address in Text Box as shown below -->Press Submit button :-
EMAIL

Step 5:-Now open your Email account(aryasamaj8@gmail.com)-->you will see your user name and password as shown below:-
forget_value

Note:- Here i have used same email address for sender and receiver .you can change receiver EMAIL address.But Sender email address should be your gmail SMTP or other server SMTP.  
Step 6:- Now again Run this application-->and Enter a wrong Email address which is not present in you emp table-->Then you will see following output as shown below:-
wrong_email

For More:-
  1. How to send mail from asp.net website free
  2. How to create setup file with database
  3. How to create captcha image on asp.net website
  4. How to print gridview data
  5. Multithreading in c#
  6. How to host asp.net website free on the server
  7. How to host asp.net website on IIS Server
  8. File handling Real Application
  9. How to create dll file in asp.net Application
For Whole Application
      Download

26 comments:

  1. hello..
    when i am running this application , i am getting following error.pls help...
    "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required."

    ReplyDelete
    Replies
    1. It may be happened due to multiple times wrong password or other things.try it with different id and password.it will work definitely.

      Delete
  2. Sir i have tried so many times with different id and password but it shows same error "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required."
    sir pls help me.

    ReplyDelete
  3. thank u very much, it helped me a lot nd is working fine

    ReplyDelete
  4. I tried this bt am getting this error.... what to do????
    "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required"

    ReplyDelete
    Replies
    1. using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.Data;
      using System.Drawing;
      using System.Linq;
      using System.Text;
      using System.Windows.Forms;
      using System.Net;
      using System.Net.Mail;
      using System.IO;


      namespace SchoolManagementSystem
      {


      public partial class Email : Form
      {
      public Email()
      {
      InitializeComponent();
      }

      private void button1_Click(object sender, EventArgs e)
      {
      try {
      MailAddress From = new MailAddress("ajitagarwal2010@gmail.com");
      MailAddress To = new MailAddress(txtTo.Text);
      MailMessage mmsg = new MailMessage(From,To);
      mmsg.Subject= txtSubj.Text;
      mmsg.Body = txtBody.Text;
      Attachment atch = new Attachment(txtattachment.Text);
      mmsg.Attachments.Add(atch);
      SmtpClient sc = new SmtpClient("smtp.gmail.com");
      sc.UseDefaultCredentials = false;
      sc.EnableSsl = true;
      sc.Credentials = new NetworkCredential("ajitagarwal2010@gmail.com", "pASSWORD");
      sc.Send(mmsg);
      Console.WriteLine("Email sent");
      }catch (Exception ex)
      {
      Console.Write(ex.Message);

      }

      }

      TRY IT

      Delete
  5. I have a question. So if you use another email from your database without changing the codes, will it still work?

    ReplyDelete
    Replies
    1. you can use any email address if this email is present in database then application will send user name password values on that respective email address...

      Delete
    2. {Label1.Text = "aryas@gmail.com"; //<--Enter your gmail id here
      Label2.Text = "94804";//<--Enter gmail password here
      smtpc.Credentials = new NetworkCredential(Label1.Text, Label2.Text); }

      Then what is this for?

      Delete
    3. Enter your gmail id and password here .It is used, any user can received his forget password value from this mail id(aryas@gmail.com)....

      Delete
  6. when i am running this application , i am getting following error.pls help...
    "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required."

    ReplyDelete
  7. hello sir , I have one query in this form...in form design view first you drag & drop one lable,textbox,& button so in coding section way you can write in lable 1 & lable2 emailed & password ?

    ReplyDelete
  8. and I try it but it give error "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required" ........... please slove my error in form that will I send you on gmail...

    ReplyDelete
  9. hello sir , please answer me
    what is the solution for this error :System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.

    ReplyDelete
    Replies
    1. hi vrunda ! Use different gmail id then it will work.......

      Delete
  10. hi !
    i need .dbo sql server. but you worked in .mdf so please send me how to work in .dbo sql server please

    ReplyDelete
  11. It's not working for me....
    error is:- Failure sending mail.

    ReplyDelete
  12. Hi,
    For these two lines
    " + ds.Tables[0].Rows[0]["UserName"] + "
    " + ds.Tables[0].Rows[0]["Password"] + "
    its showing error.
    Please suggest me what can i add to remove those errors

    ReplyDelete
    Replies
    1. Hi Venkatesh, please specify the error name.Follow every steps carefully,you will never get this error.if any problem/error inform me....

      Delete
  13. "Hi, Your UserName is : " + ds.Tables[0].Rows[0]["UserName"] + "Your Password is : " + ds.Tables[0].Rows[0]["Password"] + "";

    write it as a single-string...

    ReplyDelete
  14. I got this error.... Additional information: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

    ReplyDelete
  15. first one is resolved now I got this error...Additional information: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

    ReplyDelete
  16. How to send a forgot password code send me @ joysonabilash@gmail.com

    ReplyDelete
  17. How can solve this error at line
    smtpc.Send(email);
    System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at

    ReplyDelete
  18. I'M getting the error as "Failure sending mail." what might be the reason?

    ReplyDelete

Powered by Blogger.