简体   繁体   English

联系表单问题,将电子邮件从本地主机(IIS)发送到vb.net中的hotmail

[英]Contact form issue sending email from local host (IIS) to my hotmail in vb.net

I have designed a simple contact form using Visual studio 2005,the page runs fine but when I hit send button I get error as showing below: error in " mailclient.Send(message).I would like to send it from my localhost that Im using with visual studio to my hotmail account but it's not sending email to my hotmail account the error is as follow. 我使用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

and this is my controller class : 这是我的控制器类:

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

SomeOne can pointed out where my mistake is, and also for the line "Dim mailServerName As String = "mail.hotmail.com" " I put " mail" because Don't know exactly how to get my localmail servername. 有人可以指出我的错误所在,也可以指出“ Dim mailServerName As String =“ mail.hotmail.com””这一行,因为我不知道如何准确获取本地邮件服务器名,所以我输入了“ mail”。 Your help would be appreciated. 您的帮助将不胜感激。 Thanks in advance 提前致谢

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

Looks like they support secure connections on port 587 if you run into issues with your ISP blocking port 25. 如果您遇到ISP阻塞端口25的问题,它们似乎支持端口587上的安全连接。

Edit: 编辑:

SMTP uses port 25; SMTP使用端口25; most residential ISPs block that port. 大多数住宅ISP都阻止该端口。 Yours may be doing this. 您可能正在这样做。 Telnet is a convenient way to test this. Telnet是一种方便的测试方法。 My ISP is doing this, so when I try to connect I see this: 我的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

If however, I use the secure port (587): 但是,如果使用安全端口(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

Note that I'm running Windows 7 and the telnet client wasn't installed, so I had to add it via Control Panel > Programs > Turn Windows features on or off. 请注意,我正在运行Windows 7,但尚未安装telnet客户端,因此必须通过“控制面板”>“程序”>“打开或关闭Windows功能”添加它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM