【问题标题】:SSL Error with sending an email in VB在 VB 中发送电子邮件时出现 SSL 错误
【发布时间】:2015-03-08 03:12:13
【问题描述】:

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

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

但是,当我运行程序时,它只会返回此错误:

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

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

任何想法我哪里出错了?

【问题讨论】:

标签: vb.net


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

    Fail Sending Email Unable To Connect the Remote Server

    【讨论】:

      【解决方案3】:

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

      另外,请尝试添加以下属性

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-12-01
        • 2012-03-05
        • 2013-11-24
        • 2020-04-12
        • 2014-11-07
        • 1970-01-01
        • 2014-06-07
        • 2015-02-15
        相关资源
        最近更新 更多