在 VB 中发送电子邮件时出现 SSL 错误

SSL Error with sending an email in VB

这是我必须发送电子邮件的代码:

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Try
            Dim SmtpServer As New SmtpClient
            SmtpServer.EnableSsl = True
            Dim mail As New MailMessage
            SmtpServer.Credentials = New Net.NetworkCredential("Frrizzeh@gmail.com", "Password here")
            SmtpServer.Port = "587"
            SmtpServer.Host = "smtp.gmail.com"
            mail = New MailMessage
            mail.From = New MailAddress("Frrizzeh@gmail.com")
            mail.To.Add("Frrizzeh@gmail.com")
            mail.Subject = TextBox1.Text
            mail.Body = TextBox2.Text
            SmtpServer.Send(mail)

        Catch ex As Exception
            MsgBox(ex.Message)

        End Try

然而,当我 运行 程序时,它只是 returns 这个错误:

The SMTP server requires a secure connection or the client was not authenticated.

服务器服务器响应为:5.5.1 需要身份验证。

我哪里出错了?

尝试启用安全性较低的密码:https://www.google.com/settings/security/lesssecureapps 以便您可以从您的应用程序登录。

此外,尝试添加以下属性

SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network SmtpServer.UseDefaultCredentials = False

您可能启用了两步验证,如果启用,您需要生成应用专用密码供您使用。我回答了这个问题,并在之前的另一个问题中提供了代码。请参阅下面的 link...

Fail Sending Email Unable To Connect the Remote Server

我遇到了这个问题并通过将我的 gmail 密码更改为具有大写、小写、符号、数字的更强密码来解决它。 有趣的是,它在本地主机上运行良好,但在我的服务器上却失败了。