SMTP电子邮件发送

im *_*ess 11 c# asp.net email smtp

无法建立连接,因为目标计算机主动拒绝它127.0.0.1:25描述:在执行当前Web请求期间发生了未处理的异常.请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息.

异常详细信息:System.Net.Sockets.SocketException:无法建立连接,因为目标计算机主动拒绝它127.0.0.1:25

来源错误:

在执行当前Web请求期间生成了未处理的异常.可以使用下面的异常堆栈跟踪来识别有关异常的起源和位置的信息.

堆栈跟踪:

[SocketException(0x274d):无法建立连接,因为目标计算机主动拒绝它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(布尔值connectFailure,套接字s4,套接字s6,套接字和套接字,IP地址和地址,ConnectSocketState状态,IAsyncResult asyncResult,Int32超时,异常和异常)+224

[WebException:无法连接到远程服务器]
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消息)+1213

[SmtpException:发送邮件失败.] 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
我无法在实时连接中发送电子邮件,但在我的本地工作.

请帮帮我们.

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);
Run Code Online (Sandbox Code Playgroud)

Sar*_*fan 19

您忘记在该计算机上启动SMTP服务器

请不要告诉您该机器上没有SMTP服务器.但是,如果您必须告诉它,请参阅此页面页面

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