简体   繁体   English

System.Net.Mail.SmtpException SMTP服务器需要安全连接,或者客户端未通过身份验证

[英]System.Net.Mail.SmtpException The SMTP server requires a secure connection or the client was not authenticated

I am trying to send SMTP email from my vb.net form application. 我试图从我的vb.net表单应用程序发送SMTP电子邮件。 When applying this code, I get the error below. 应用此代码时,出现以下错误。 What am I doing wrong? 我究竟做错了什么?

Code: 码:

Imports System.Net.Mail

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Dim SmtpServer As New SmtpClient()
            Dim mail As New MailMessage()
            SmtpServer.Credentials = New  _
            Net.NetworkCredential("myemail@gmail.com", "mypassword")
            SmtpServer.Port = 587
            SmtpServer.Host = "smtp.gmail.com"
            mail = New MailMessage()
            mail.From = New MailAddress("myemail@gmail.com")
            mail.To.Add("sendto@hotmail.co.uk")
            mail.Subject = "Test Mail"
            mail.Body = "This is for testing SMTP mail from GMAIL"
            SmtpServer.Send(mail)
            MsgBox("mail send")
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
End Class

Error: 错误:

System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. System.Net.Mail.SmtpException:SMTP服务器需要安全连接,或者客户端未通过身份验证。 The server response was: 5.7.0 Must issue a STARTTLS command first 服务器响应为:5.7.0必须首先发出STARTTLS命令

错误信息

  1. Check if the login and password are correct; 检查登录名和密码是否正确;
  2. Use SmtpServer.EnableSsl = true; 使用SmtpServer.EnableSsl = true;
  3. Gmail has disabled access using credentials (user and password) by default, you need go to this page: https://www.google.com/settings/security/lesssecureapps and "Enable Less Secure Apps", this means: "Enable login by apps using user and password". Gmail默认已禁用使用凭据(用户和密码)的访问权限,您需要转到以下页面: https//www.google.com/settings/security/lesssecureapps和“启用安全性较低的应用程序”,这意味着:“启用登录通过使用用户名和密码的应用程序”。 More details here: https://support.google.com/accounts/answer/6010255 此处有更多详细信息: https : //support.google.com/accounts/answer/6010255

See if this helps; 看看是否有帮助; Add

SmtpServer.EnableSSL= true

I know this was last year but I thought I should publish the answer as five minutes ago I had the same issue. 我知道这是去年,但是我认为我应该发布答案,因为五分钟前我遇到了同样的问题。

Basically your log in credentials are incorrect and need changing. 基本上,您的登录凭据不正确,需要更改。

Also thanks for the previous answer has that piece of code allows me to send emails over SSL encryption (I Hope LOL). 也感谢您先前的回答,那段代码使我可以通过SSL加密发送电子邮件(我希望大声笑)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM