Try
connection.Open()
Dim cmdText As String = ("SELECT password from users1 WHERE email =" & "'" & txtemail.Text & "'")
Dim cmd As New MySqlCommand(cmdText, connection)
Dim password As String = cmd.ExecuteScalar()
If password Is Nothing Then
lblerror.Text = "Invalid Email Address. Please Try Again!"
Else
txtpassword.Text = password
'!!! UPDATE THIS VALUE TO YOUR EMAIL ADDRESS
Const fromAddress As String = "test@test.com"
'(1) Create the MailMessage instance
Dim mm As New MailMessage(fromAddress, txtemail.Text)
'(2) Assign the MailMessage's properties
mm.Subject = "Password"
mm.Body = "Your Password is " + txtpassword.Text
mm.IsBodyHtml = false
'(3) Create the SmtpClient object
Dim smtp As New SmtpClient
'(4) Send the MailMessage (will use the Web.config settings)
smtp.Send(mm)
lblerror.Text = "Your Password has been sent. !"
End If
Catch ex As Exception
lblerror.Text = "Your Password has been sent. !"
Finally
connection.Close()
End Try