Try
Dim rand As New Random()
randomCode = (rand.Next(999999)).ToString()
Dim smtp As New SmtpClient
Dim mail As New MailMessage
smtp.UseDefaultCredentials = False
smtp.Credentials = New Net.NetworkCredential("studentinfosytem2022@gmail.com", "bbuthrohpkmvhyav")
smtp.Port = 587
smtp.EnableSsl = True
smtp.Host = "smtp.gmail.com"
mail = New MailMessage
mail.From = New MailAddress("studentinfosytem2022@gmail.com")
mail.To.Add(txtEmail.Text)
mail.Subject = "Password Recovery"
mail.Body = "Your OTP Password recovery is " + randomCode
mail.IsBodyHtml = True
smtp.Send(mail)
MessageBox.Show("OTP was successfully sent to your Email. Please check your inbox.", "Sent", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
MsgBox(ex.Message.ToString, MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly, "Failed to send Message!")
End Try
i always get the error "The SMTP server requires a secure connection or the Client was not authenticated." even i already enabled the 2-step verification and created app password on google.
how to fix this?