title: SMTP Email Sending
body: <p>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. Please review the stack trace for more information about the error and where it originated in the code.</p>
  
  <blockquote>
    <p>Exception Details:
    System.Net.Sockets.SocketException: No
    connection could be made because the
    target machine actively refused it
    127.0.0.1:25</p>
  </blockquote>
  
  <p>Source Error:</p>
  
  <blockquote>
    <p>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.</p>
    
    <p>Stack Trace:</p>
    
    <p>[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<br>
    System.Net.Sockets.Socket.InternalConnect(EndPoint
    remoteEP) +35<br>
    System.Net.ServicePoint.ConnectSocketInternal(Boolean
    connectFailure, Socket s4, Socket s6,
    Socket&amp; socket, IPAddress&amp; address,
    ConnectSocketState state, IAsyncResult
    asyncResult, Int32 timeout, Exception&amp;
    exception) +224</p>
    
    <p>[WebException: Unable to connect to
    the remote server]<br>
    System.Net.ServicePoint.GetConnection(PooledStream
    PooledStream, Object owner, Boolean
    async, IPAddress&amp; address, Socket&amp;
    abortSocket, Socket&amp; abortSocket6,
    Int32 timeout) +5483819<br>
    System.Net.PooledStream.Activate(Object
    owningObject, Boolean async, Int32
    timeout, GeneralAsyncDelegate
    asyncCallback) +202<br>
    System.Net.PooledStream.Activate(Object
    owningObject, GeneralAsyncDelegate
    asyncCallback) +21<br>
    System.Net.ConnectionPool.GetConnection(Object
    owningObject, GeneralAsyncDelegate
    asyncCallback, Int32 creationTimeout)
    +332    System.Net.Mail.SmtpConnection.GetConnection(String
    host, Int32 port) +160<br>
    System.Net.Mail.SmtpTransport.GetConnection(String
    host, Int32 port) +159<br>
    System.Net.Mail.SmtpClient.GetConnection()
    +35    System.Net.Mail.SmtpClient.Send(MailMessage
    message) +1213</p>
    
    <p>[SmtpException: Failure sending mail.]
    System.Net.Mail.SmtpClient.Send(MailMessage
    message) +1531<br>
    Checkout.btnSend_Click(Object sender,
    EventArgs e) +2675<br>
    System.Web.UI.WebControls.Button.OnClick(EventArgs
    e) +111<br>
    System.Web.UI.WebControls.Button.RaisePostBackEvent(String
    eventArgument) +110<br>
    I can't send email in live connection but in my local its working.</p>
  </blockquote>
  
  <p>please help me guys.</p>
  
  <blockquote>
    <p>System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
    eventArgument) +10<br>
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
    sourceControl, String eventArgument)
    +13    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection
    postData) +36<br>
    System.Web.UI.Page.ProcessRequestMain(Boolean
    includeStagesBeforeAsyncPoint, Boolean
    includeStagesAfterAsyncPoint) +1565</p>
  </blockquote>
  
  <p>Version Information: Microsoft .NET Framework Version:2.0.50727.3615; ASP.NET Version:2.0.50727.3618 </p>
  
  <p>here's my C# code..</p>
  
  <pre><code>        SmtpClient SmtpMail = new SmtpClient();
          SmtpMail.Host = "localhost";
  
          //delete session cookie
          Response.Cookies["session"].Expires = DateTime.Now.AddYears(-30);
  
          SmtpMail.Send(objEmail);
  </code></pre>