需要STMP身份验证

时间:2020-03-02 07:32:42

标签: vb.net smtpclient

以前有工作,但是上个月突然出现了这个问题。无需更改代码

我的问题是,当我尝试在VB.net中使用SmtpClient发送电子邮件时,它会以

的形式抛出异常错误消息

System.Net.Mail.SmtpException:SMTP服务器需要一个安全的 连接或客户端未通过身份验证。服务器响应 原为:5.7.0需要身份验证。

我是否也使用应用密码/ less secure app access并出现相同错误!

以下代码:

Using client As New SmtpClient(AccountOption.AccMailSMTP, AccountOption.AccMailPort) 'SMTP: smtp.gmail.com & Port: 587

    message = New MailMessage(ParamEmail, fileReaderEmail) 'From Email & To Email

        Dim rich As New RichEditControl
        Dim test As New MemoryStream(AccountOption.AccMailDefaultContent)

        rich.LoadDocument(test, DocumentFormat.Html)
        message.Attachments.Add(New Attachment(file))
        message.Subject = subject.Name & " For " & IO.Path.GetFileName(debtorFolder)
        message.IsBodyHtml = True
        message.Body = rich.HtmlText

        client.UseDefaultCredentials = True
        client.Credentials = New Net.NetworkCredential(ParamEmail, ParamPassword) 'To Email & The Password / App Password
        client.DeliveryMethod = SmtpDeliveryMethod.Network
        client.Timeout = 10000
        client.EnableSsl = True

        Try
            client.Send(message)
        Catch ex As Exception
            Throw ex
        End Try
End Using

我尝试过的链接。但还是一样:

How do I send an email with Gmail and SmtpClient when the sending account uses two factor authentication?

The server response was: 5.7.0 Authentication Required. Learn more at

1 个答案:

答案 0 :(得分:0)

嗨,在安全面板中转到您的Google帐户 enter image description here

点击“关闭/开启访问权限(推荐)”

在打开的面板中必须将其打开

enter image description here