title: Mail Sending problem
body: <p>I have used this code to send mails but I am not getting any error but I'm able to receive the mail. The default smtp server is also set to "127.0.0.1" as my local host in relay mail in the "inetmgr" but I'm still not able to receive the mail. I don't know where the problem is.</p>
  
  <p>In <code>emailsender.cs</code> class this is the code:</p>
  
  <pre><code>public void SendEmail(string To, String Subject, String Body, String uname)
  {
      string body = "Hi " + uname + ",\n\n \t" + Body + "\n" + " \n Regards, \n LMS Team" + "\n\n\tSent at: " + DateTime.Now + " \n\n\t\t---- This is an auto generated mail. Please do not reply.";
      try
      {
          try
          {
              MailMessage Message = new MailMessage();
              Message.From = new MailAddress("karhik.varadarajan@asteor.com");
  
              if (!string.IsNullOrEmpty(To))
                  Message.To.Add(new MailAddress(To));
              Message.Subject = Subject;
              Message.Body = body;
              try
              {
                  SmtpClient smtpClient = new SmtpClient("localhost");
                  smtpClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
                  smtpClient.Port = 25;
                  smtpClient.UseDefaultCredentials = false;
                  smtpClient.Send(Message);
              }
              catch (System.Web.HttpException ehttp)
              {
                  throw new Exception("Email Sending Failed", ehttp);
              }
          }
          catch (IndexOutOfRangeException ex)
          {
              throw new IndexOutOfRangeException("Email Sending Failed", ex);
          }
      }
      catch (System.Exception ex)
      {
          throw new Exception("Email Sending Failed", ex);
      }
  }
  </code></pre>
  
  <p>In the <code>.aspx</code> file:</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
      EmailSender email = new EmailSender();
      email.SendEmail("karhik.varadarajan@asteor.com", "testingmail", "this is a test mail", "From");
  }
  </code></pre>