title: Can we send mails from localhost using asp.net and c#?
body: <p>i am using <code>using System.Net.Mail;</code> </p>
  
  <p>and following code to send mail</p>
  
  <pre><code>MailMessage message = new MailMessage();
          SmtpClient client = new SmtpClient();
  
          // Set the sender's address
          message.From = new MailAddress("fromAddress");
  
       // Allow multiple "To" addresses to be separated by a semi-colon
          if (toAddress.Trim().Length &gt; 0)
          {
              foreach (string addr in toAddress.Split(';'))
              {
                  message.To.Add(new MailAddress(addr));
              }
          }
        // Allow multiple "Cc" addresses to be separated by a semi-colon
          if (ccAddress.Trim().Length &gt; 0)
          {
              foreach (string addr in ccAddress.Split(';'))
              {
                  message.CC.Add(new MailAddress(addr));
              }
          }
          // Set the subject and message body text
          message.Subject = subject;
          message.Body = messageBody;
  
          // Set the SMTP server to be used to send the message
          client.Host = "YourMailServer";
  
          // Send the e-mail message
          client.Send(message);
  </code></pre>
  
  <p>for Host i am providing <code>client.Host = "localhost";</code> </p>
  
  <p>for this its falling with error </p>
  
  <blockquote>
    <p>No connection could be made because the target machine actively
    refused it <i>some_ip_address_here</i></p>
  </blockquote>
  
  <p>and when i use <code>client.Host = "smtp.gmail.com";</code></p>
  
  <p>i get following error </p>
  
  <blockquote>
    <p>A connection attempt failed because the connected party did not
    properly respond after a period of time, or established connection
    failed because connected host has failed to respond</p>
  </blockquote>
  
  <p>i am not able to send mail through localhost.
  Please help me out, i am new to c# please correct me in code where i am going wrong..?</p>