0

我使用 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”,因为不知道如何获取我的本地邮件服务器名。您的帮助将不胜感激。提前致谢

4

1 回答 1

0

您应该通过 smtp.live.com 发送邮件。请参阅http://windows.microsoft.com/en-CA/hotmail/send-receive-email-from-mail-client

如果您遇到 ISP 阻塞端口 25 的问题,它们似乎支持端口 587 上的安全连接。

编辑:

SMTP 使用端口 25;大多数住宅 ISP 都会阻止该端口。你的可能正在这样做。Telnet 是一种方便的测试方法。我的 ISP 正在这样做,所以当我尝试连接时,我看到:

C:\Users\foo>telnet smtp.live.com 25
Connecting To smtp.live.com...Could not open connection to the host, on port 25:
 Connect failed

但是,如果我使用安全端口(587):

C:\Users\foo>telnet smtp.live.com 587
220 BLU0-SMTP254.blu0.hotmail.com Microsoft ESMTP MAIL Service, Version: 6.0.379
0.4675 ready at  Mon, 10 Dec 2012 11:43:31 -0800

请注意,我正在运行 Windows 7 并且未安装 telnet 客户端,因此我必须通过控制面板 > 程序 > 打开或关闭 Windows 功能来添加它。

于 2012-12-09T22:42:54.780 回答