1
基本上,我试图在按下按钮时发送电子邮件。通过Gmail发送电子邮件时发生错误SMTP
使用下面的代码,我得到一个错误,说'SMTP服务器需要一个安全的连接或客户端未经过身份验证'。
什么是造成此错误?
Imports System.Net.Mail
Private Sub Button1_Click_2(sender As Object, e As EventArgs) Handles Button1.Click
Try
Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
SmtpServer.Credentials = New _
Net.NetworkCredential("[email protected]", "MYPASSWORD")
SmtpServer.EnableSsl = True
SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network
SmtpServer.UseDefaultCredentials = False
SmtpServer.Port = 587
SmtpServer.Host = "smtp.gmail.com"
mail = New MailMessage()
mail.From = New MailAddress("MYEMAIL")
mail.To.Add("SENDINGADRESS")
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
iv添加了所有这些属性,但不幸的是错误仍然出现:SMTP服务器需要安全连接或客户端未通过身份验证。服务器的回应是:5.5.1验证required.It还说看看116线这是SmtpServer.send(邮件) –
你确定用户名和密码是正确的? – jessegavin
是啊刚刚检查 –