0% found this document useful (0 votes)
3 views1 page

Send

The document contains a subroutine for sending a password recovery email to a user. It retrieves the username and password from a database based on the provided email address and sends an email with the password if found. If the email does not match any records, it displays an error message.

Uploaded by

lkishomy02
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Send

The document contains a subroutine for sending a password recovery email to a user. It retrieves the username and password from a database based on the provided email address and sends an email with the password if found. If the email does not match any records, it displays an error message.

Uploaded by

lkishomy02
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Protected Sub SendEmail(sender As Object, e As EventArgs)

Dim username As String = String.Empty


Dim password As String = String.Empty
Dim constr As String =
ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using con As New SqlConnection(constr)
Using cmd As New SqlCommand("SELECT Username, [Password] FROM Users WHERE
Email = @Email")
cmd.Parameters.AddWithValue("@Email", txtEmail.Text.Trim())
cmd.Connection = con
con.Open()
Using sdr As SqlDataReader = cmd.ExecuteReader()
If sdr.Read() Then
username = sdr("Username").ToString()
password = sdr("Password").ToString()
End If
End Using
con.Close()
End Using
End Using
If Not String.IsNullOrEmpty(password) Then
Dim mm As New MailMessage("[email protected]", txtEmail.Text.Trim)
mm.Subject = "Password Recovery"
mm.Body = String.Format("Hi {0},<br /><br />Your password is {1}.<br
/><br />Thank You.", username, password)
mm.IsBodyHtml = True
Dim smtp As New SmtpClient()
smtp.Host = "smtp.gmail.com"
smtp.EnableSsl = True
Dim NetworkCred As New NetworkCredential()
NetworkCred.UserName = "[email protected]"
NetworkCred.Password = "<Password>"
smtp.UseDefaultCredentials = True
smtp.Credentials = NetworkCred
smtp.Port = 587
smtp.Send(mm)
lblMessage.ForeColor = Color.Green
lblMessage.Text = "Password has been sent to your email address."
Else
lblMessage.ForeColor = Color.Red
lblMessage.Text = "This email address does not match our records."
End If
End Sub

You might also like