title: Sending an Email through gmail SMTP Server (SSL)
body: <p>I know there's a lot of example on how to send an email using C# but I am really running into some issues and I can't make it to work.</p>
  
  <p>I always get <code>"Failure sending mail"</code> error, <code>Unable to connect to the remote server - No connection could be made because the active machine actively refused it (IP address here)</code>.</p>
  
  <p>What does this error mean? And how do I fix this?</p>
  
  <p>Any help will be much appreciated</p>
  
  <p>Here's the code that I've been using: (although I already did try a lot of things)</p>
  
  <pre><code>string SendersAddress = "test@gmail.com";
  string ReceiversAddress = "test1@gmail.com";
  const string SendersPassword = "test-pass-here";
  const string subject = "Testing";
  const string body = "Hi This Is my Mail From Gmail";
  try
  {
      SmtpClient smtp = new SmtpClient
          {
              Host = "smtp.gmail.com",
              Port = 587,
              EnableSsl = true,
              DeliveryMethod = SmtpDeliveryMethod.Network,
              Credentials = new NetworkCredential(SendersAddress, SendersPassword),
              Timeout = 3000
          };
      MailMessage message = new MailMessage(SendersAddress, ReceiversAddress, subject, body);
      smtp.Send(message);
  }
  catch (Exception ex)
  {
  }
  </code></pre>
  
  <p>Thanks!</p>