[英]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命令
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.