Problem with sending email
<p>The send method of SMTP is always throwing an exception. The message is : <strong>Failure sending mail</strong></p>

<p>Here is my code:</p>

<pre><code>MailMessage mm = new MailMessage();
mm.To.Add("Yuvraj.dhot@xxxxx.co.in");

mm.From = new MailAddress("Kumar.Chaudhari@xxxxx.co.in");
mm.Subject = "Ant Subject";
mm.Body = "Body Cha MEssag here ";

SmtpClient ss = new SmtpClient("localhost");

ss.EnableSsl = false;

try
{
    **ss.Send(mm);**
    Result.Text = "Message Sent";
    Result.ForeColor = System.Drawing.Color.Green;
}
catch (SmtpException ex)
{
    Result.Text = "Message Not Sent : \n\n " + ex.Message;
    Result.ForeColor = System.Drawing.Color.Red;
}
</code></pre>

<p>I also tried using</p>

<pre><code>ss.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
</code></pre>

<p>Now it doesn't throw any exception, it executes fine but receiver does not receive any mail in his inbox.</p>

<p>How can I fix this?</p>

<p>Edit - This is the stack trace im getting</p>

<pre><code>    Message=Failure sending mail. Source=System StackTrace: at System.Net.Mail.SmtpClient.Send
(MailMessage message) at WebApplication1._Default.Page_Load(Object sender, EventArgs e) in D:\Emcure-
Kumar\Work\Not in Use\WebApplication1\WebApplication1\Default.aspx.cs:line 30 InnerException: 
System.Net.WebException Message=Unable to connect to the remote server Source=System StackTrace: –
    at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async,
 IPAddress&amp; address, Socket&amp; abortSocket, Socket&amp; abortSocket6, Int32 timeout) at 
System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, 
GeneralAsyncDelegate asyncCallback) at System.Net.PooledStream.Activate(Object owningObject, 
GeneralAsyncDelegate asyncCallback) at System.Net.ConnectionPool.GetConnection(Object owningObject, 
GeneralAsyncDelegate asyncCallback, Int32 creationTimeout)
    at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port) at 
System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port) at 
System.Net.Mail.SmtpClient.GetConnection() at System.Net.Mail.SmtpClient.Send(MailMessage message) 
InnerException: System.Net.Sockets.SocketException Message=No connection could be made because the 
target machine actively refused it 127.0.0.1:25 Source=System ErrorCode=10061 NativeErrorCode=10061
</code></pre>
