2012-02-14 31 views
0

我想從我的vb.net表格應用程序發送SMTP電子郵件。應用此代碼時,我收到以下錯誤。我究竟做錯了什麼?System.Net.Mail.SmtpException SMTP服務器要求安全連接或客戶端沒有經過認證

代碼:

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("[email protected]", "mypassword") 
      SmtpServer.Port = 587 
      SmtpServer.Host = "smtp.gmail.com" 
      mail = New MailMessage() 
      mail.From = New MailAddress("[email protected]") 
      mail.To.Add("[email protected]") 
      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 

錯誤:

System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first

Error Message

回答

0

看是否有此幫助; Add

SmtpServer.EnableSSL= true 
-1

我知道這是去年,但我想我應該在五分鐘前發佈答案,我有同樣的問題。

基本上你的登錄憑證不正確,需要改變。

也感謝以前的答案有一段代碼,讓我送過來的SSL加密郵件(我希望LOL)。

相關問題