The HTML code:
Email:
<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
<br />
<asp:Button ID="btnSend" runat="server" Text="Send" />
Namespace:
Imports System.Data
Imports System.Data.SqlClient
Imports System.Net.Mail
To send the forgotten password
Protected Sub btnSend_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSend.Click
Dim message As String
Try
Dim ds As New DataSet()
Using con As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
con.Open()
Dim cmd As New SqlCommand("SELECT UserName,Password FROM Users Where Email= '" & txtEmail.Text.Trim() & "'", con)
Dim da As New SqlDataAdapter(cmd)
da.Fill(ds)
con.Close()
End Using
If ds.Tables(0).Rows.Count > 0 Then
Dim Msg As 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 Details<br/><br/>Your Username: " & Convert.ToString(ds.Tables(0).Rows(0)("UserName")) & "<br/><br/>Your Password: " & Convert.ToString(ds.Tables(0).Rows(0)("Password")) & "<br/><br/>"
Msg.IsBodyHtml = True
' your remote SMTP server IP.
Dim smtp As New SmtpClient()
smtp.Host = "smtp.gmail.com"
smtp.Port = 587
'587
'50484
smtp.Credentials = New System.Net.NetworkCredential("emailaddress@gmail.com", "password")
smtp.EnableSsl = True
smtp.Send(Msg)
'Msg = null;
message = "Your Password Details Sent to your mail"
ClientScript.RegisterStartupScript([GetType](), "alert", (Convert.ToString("alert('") & message) + "');", True)
' Clear the textbox valuess
txtEmail.Text = ""
Else
message = "The email you entered not exist."
ClientScript.RegisterStartupScript([GetType](), "alert", (Convert.ToString("alert('") & message) + "');", True)
End If
Catch ex As Exception
message = "Error Occured. Try Again."
ClientScript.RegisterStartupScript([GetType](), "alert", (Convert.ToString("alert('") & message) + "');", True)
'Console.WriteLine("{0} Exception caught.", ex)
End Try
End Sub
NOTE:
You should change the "emailaddress@gmail.com" and the "password"
Try it in your own