2012-11-28 25 views
0

這裏是我的代碼(是的,我刪我的電子郵件/密碼)(當你點擊按鈕)SMTP.Send(郵件)錯誤

Dim Mail As New MailMessage 
Mail.Subject = "test email" 
Mail.To.Add("*****") 
Mail.From = New MailAddress("*****") ' 
Mail.Body = "This is an email!" 
Dim SMTP As New SmtpClient("smtp.gmail.com") 
SMTP.EnableSsl = True 
SMTP.Credentials = New System.Net.NetworkCredential("*****", "*****") 
SMTP.Port = 587 
SMTP.Send(Mail) 
MsgBox("Sent Successfully") 

SMTP服務器要求安全連接或客戶端未通過身份驗證。服務器響應是:5.5.1需要身份驗證。瞭解更多(鏈接這不利於)

回答

1

已解決! 我永遠不會猜到。 谷歌不讓我使用我的帳戶,因爲它被黑客入侵。它顯然是在我編寫代碼時被黑客入侵...

0

僅供參考,更安全的版本將是

Using mail As MailMessage = New MailMessage 
     mail.Subject = "test email" 
     mail.To.Add("*****") 
     mail.From = New MailAddress("*****") ' 
     mail.Body = "This is an email!" 
     Using smtp As New SmtpClient("smtp.gmail.com") 
      smtp.EnableSsl = True 
      smtp.Credentials = New System.Net.NetworkCredential("*****", "*****") 
      smtp.Port = 587 
      smtp.Send(mail) 
     End Using 
    End Using 
    MsgBox("Sent Successfully") 

這將確保mailsmtp對象得到清理,無論是否發生異常。

+0

不能工作第6行的錯誤 – user1797443