c# - The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required? - Stack Overflow

PHOTO EMBED

Wed Jan 18 2023 20:39:56 GMT+0000 (Coordinated Universal Time)

Saved by @javicinhio

Dim emailTo As String = TxtEmail.Text.Trim()
        If emailTo.Length > 10 Then
            Try
                Dim Smtp_Server As New SmtpClient
                Dim e_mail As New MailMessage()
                Smtp_Server.UseDefaultCredentials = False
                Smtp_Server.Credentials = New Net.NetworkCredential("myemail@gmail.com", "***16-digit-code***")
                Smtp_Server.Port = 587
                Smtp_Server.EnableSsl = True
                Smtp_Server.Host = "smtp.gmail.com"

                e_mail = New MailMessage()
                e_mail.From = New MailAddress("myemailaddress@gmail.com")
                e_mail.To.Add(emailTo)
                e_mail.Subject = "Login OTP"
                e_mail.IsBodyHtml = False
                e_mail.Body = "some text here"
                Smtp_Server.Send(e_mail)
                MessageBox.Show("Your login OTP has been sent to " & emailTo)
                LblOTPSuccess.Visible = True
                TxtOTP.Visible = True
                BtnVerifyOTP.Visible = True
                TxtOTP.Focus()
            Catch error_t As Exception
                MessageBox.Show(error_t.ToString, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
        Else
            MessageBox.Show("Email address is invalid or too short", "Invalid Email", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If
content_copyCOPY

https://stackoverflow.com/questions/18503333/the-smtp-server-requires-a-secure-connection-or-the-client-was-not-authenticated