我使用 Visual Studio 2005 设计了一个简单的联系表单,该页面运行良好,但是当我点击发送按钮时,我收到如下所示的错误:“mailclient.Send(message) 中的错误。我想从我的本地主机发送它我与visual studio一起使用到我的hotmail帐户,但它没有向我的hotmail帐户发送电子邮件,错误如下。
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
Source Error:
Line 24: Dim mailclient As SmtpClient = New SmtpClient
Line 25: mailclient.Host = mailServerName
Line 26: mailclient.Send(message)
Line 27: message.Dispose()
Line 28: End Sub
这是我的控制器类:
Imports System.Net.Mail
Partial Class ContactUs
Inherits System.Web.UI.Page
Protected Sub textComments_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
End Sub
Protected Sub textComments_TextChanged1(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtComments.TextChanged
End Sub
Protected Sub Send_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtSend.Click
SendMail(txtEmail.Text, txtComments.Text)
End Sub
Private Sub SendMail(ByVal From As String, ByVal body As String)
Dim mailServerName As String = "mail.hotmail.com"
Dim message As MailMessage = New MailMessage(From, "Myaddress@hotmail.com", "Feedback", body)
Dim mailclient As SmtpClient = New SmtpClient
mailclient.Host = mailServerName
mailclient.Send(message)
message.Dispose()
End Sub
End Class
有人可以指出我的错误在哪里,并且对于“Dim mailServerName As String =”mail.hotmail.com”这行我放了“mail”,因为不知道如何获取我的本地邮件服务器名。您的帮助将不胜感激。提前致谢