VB.NET SMTP gmail 不工作

VB.NET SMTP gmail not working

我不断收到此错误消息 任何解决方案?

"smtp server requires a secure connection or the client was not authenticated 5.5.1"

Public 子发送代码()

    GenerateCode()

    Dim Mail As New MailMessage
    Dim SMTPServer As New SmtpClient("smtp.gmail.com")
    Try
        SMTPServer.Credentials = New  _
       Net.NetworkCredential("email@gmail.com", "password")
        Mail.From = New MailAddress("email@gmail.com")
        Mail.To.Add("email2@gmail.com")
        Mail.Subject = "Confirmation Code"
        Mail.Body = Me.Firstname & " " & Me.LastN & " This is a NO_REPLY confirmation Email, Confirmation Code:" & Me.ConfirmationCode & ""
        SMTPServer.Port = 587
        SMTPServer.EnableSsl = True
        SMTPServer.Send(Mail)
        MsgBox("mail sent")
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
End Sub

您需要将端口设置为 465 并将 SSL/TLS 设置为自动...

我已成功使用此代码...https://www.emailarchitect.net/easendmail/kb/vbnet.aspx?cat=2