Sending SMTP Email

No connection could be made because the target machine actively refused it 127.0.0.1:25 Description: An unhandled exception occurred during the execution of the current web request. Check the stack trace for more information about the error and where it appeared in the code.

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

Source Error:

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

Stack trace:

[SocketException (0x274d): No connection can 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 & amp; socket, IPAddress & address, ConnectSocketState status, IAsyncResult asyncResult, Int32 timeout, exception and amp; exception) +224

[WebException: unable to connect to 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 (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, port Int32) +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 to send 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 cannot send email in live mode, but it works in my local mode.

Please help me guys.

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

Version Information: Microsoft.NET Framework Version: 2.0.50727.3615; ASP.NET Version: 2.0.50727.3618

here is my c # code ..

SmtpClient SmtpMail = new SmtpClient(); SmtpMail.Host = "localhost"; //delete session cookie Response.Cookies["session"].Expires = DateTime.Now.AddYears(-30); SmtpMail.Send(objEmail); 
+11
source share
2 answers

You forgot to start the SMTP server on this machine

Please do not say that you do not have an SMTP server on this computer. But, if you must say this, refer to this page and this page as well

Even if you configure a local SMTP server, your emails will most likely end up in the spam folder. It is better to use the SMTP server of your mail provider. If you use Gmail, look here.

+18
source

I got an error with smtp services installed but not running. To start the services on the local machine with SMTP already installed, here are the steps I took:

  1. Open Server Manager
  2. Select Local Server
  3. Enter "smtp" in the filter field under SERVICES (see. Image)
  4. Right-click the SMTP Protocol Service and select Start Services.

Server manager with Local Server selected and services filtered to smtp

0
source

All Articles