2011-04-06 267 views
7

由于目标机器主动拒绝它,因此无法建立连接127.0.0.1:25 描述:执行当前Web请求期间发生未处理的异常。请查看堆栈跟踪以获取有关该错误的更多信息以及源代码的位置。SMTP电子邮件发送

Exception Details: System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:25

源错误:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[SocketException (0x274d): No connection could be made because the target machine actively refused it 127.0.0.1:25] System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) +239
System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP) +35
System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) +224

[WebException: Unable to connect to the remote server]
System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout) +5483819
System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback) +202
System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) +21
System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) +332 System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port) +160
System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port) +159
System.Net.Mail.SmtpClient.GetConnection() +35 System.Net.Mail.SmtpClient.Send(MailMessage message) +1213

[SmtpException: Failure sending mail.] System.Net.Mail.SmtpClient.Send(MailMessage message) +1531
Checkout.btnSend_Click(Object sender, EventArgs e) +2675
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
I can't send email in live connection but in my local its working.

请帮我家伙。

System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

版本信息:Microsoft .NET Framework版本:2.0.50727.3615; ASP.NET版本:2.0.50727.3618

这里是我的C#代码..

 SmtpClient SmtpMail = new SmtpClient(); 
     SmtpMail.Host = "localhost"; 

     //delete session cookie 
     Response.Cookies["session"].Expires = DateTime.Now.AddYears(-30); 

     SmtpMail.Send(objEmail); 
+2

您的计算机上是否还有邮件服务器?你有没有尝试'telnet localhost 25'? – 2011-04-06 08:07:48

+0

你使用什么SMTP服务器? – 2011-04-06 08:08:18

+0

...并且不要忘记检查您的(Windows)防火墙... – m0sa 2011-04-06 08:09:18

回答

14

你忘了启动您的SMTP服务器的机器上

请不要告诉你没有一个该机器上的SMTP服务器。但是,如果您必须知道,请参阅此pagethis页面也

即使您配置本地SMTP服务器,您的电子邮件最有可能最终在垃圾邮件文件夹中。更好地使用电子邮件提供商的SMTP服务器。如果您使用的是Gmail,请查看here

+0

是的,但在我的情况下,尽管SMTP服务已打开,尽管SMTP服务器处于启用状态并且功能正常,但仍会出现相同的127.0.0.1:25错误。它之前在工作,但由于某种安全设置更改(但不是SMTP中的设置)而突然停止。 – Dexter 2013-09-10 15:01:42