我寫了下面的代碼從VB.net窗體發送電子郵件。 這裏是我的代碼從VB.net發送電子郵件Windows窗體
Try
Dim message As System.Net.Mail.MailMessage
Dim smtp As New System.Net.Mail.SmtpClient("smtp.gmail.com")
Dim fromMailAddress As System.Net.Mail.MailAddress
Dim toMailAddress As System.Net.Mail.MailAddress
fromMailAddress = New System.Net.Mail.MailAddress("[email protected]")
toMailAddress = New System.Net.Mail.MailAddress("[email protected]")
message = New System.Net.Mail.MailMessage()
message.From = toMailAddress
message.To.Add(fromMailAddress)
message.Subject = "TestFromVB"
message.Body = "Test Message"
smtp.EnableSsl = True
smtp.UseDefaultCredentials = False
smtp.Credentials = New System.Net.NetworkCredential("[email protected]", "password")
smtp.DeliveryMethod = Net.Mail.SmtpDeliveryMethod.Network
smtp.Send(message)
MessageBox.Show("sent...")
Catch ex As Exception
MessageBox.Show("error" + ex.Message + "\n" + ex.InnerException.ToString())
End Try
每當我點擊一個按鈕發送,應該發送電子郵件到指定的地址。卜這段代碼是給一些錯誤說無法連接到遠程計算機....
這裏是例外
截圖有人可以幫我解決這個問題。或者請建議您是否有任何工作樣本。