title: Whitelist IP gmail smtp - System.Net.Mail.SmtpException: Failure sending mail
body: <p>I have the following code that sends an email. It works fine locally but when deploying on my hostgator windows server I get the exception below.</p>
  
  <p>I would guess that I need to whitelist my servers IP in gmail somwhow but how do I do that?</p>
  
  <p>Code:</p>
  
  <pre><code>            var fromAddress = new MailAddress("XXX@gmail.com", "From XXX");
              var toAddress = new MailAddress("XXX@gmail.com", "To XXX");
              const string fromPassword = "XXX";
              const string subject = "Email Headline";
              string body = "Email Body";
  
              var smtp = new SmtpClient
              {
                  Host = "smtp.gmail.com",
                  Port = 587,
                  EnableSsl = true,
                  DeliveryMethod = SmtpDeliveryMethod.Network,
                  UseDefaultCredentials = false,
                  Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
              };
              using (var message = new MailMessage(fromAddress, toAddress)
              {
                  Subject = subject,
                  Body = body
              })
              {
                  smtp.Send(message);
              }
  </code></pre>
  
  <p>Exception:</p>
  
  <pre><code>System.Net.Mail.SmtpException: Failure sending mail. ---&gt; System.Net.WebException: Unable to connect to the remote server ---&gt; System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions 173.194.77.109:587
  </code></pre>