title: SMTP server requires a secure connection - gmail
body: <p>I am running an ASP.Net application on windows azure and I need to send an email from it. I am trying to send it using my gmail account as follows, however when I attempt to send it, I get the following error:</p>
  
  <blockquote>
    <p>The SMTP server requires a secure connection or the client was not
    authenticated. The server response was: 5.5.1 Authentication Required.
    Learn more at</p>
  </blockquote>
  
  <p>The code:</p>
  
  <pre><code>        private static readonly string EMAIL_ADDRESS = "mymail@gmail.com";
          private static readonly string EMAIL_FROM = "MY FROM NAME";
          private static readonly string EMAIL_PASS = "my Password";
          private static readonly string EMAIL_HOST = "smtp.gmail.com";
          private static readonly int EMAIL_PORT = 587;
          private static readonly bool EMAIL_SSL = true;
          private static readonly SmtpDeliveryMethod EMAIL_DELIVERY_METHOD = SmtpDeliveryMethod.Network;
          private static readonly bool EMAIL_DEFAULT_CREDENTIALS = false;
  
  
          public static void SendEmail(string recipientEmail, string subject, string body) {
              var fromAddress = new MailAddress(EMAIL_ADDRESS, EMAIL_FROM);
              var toAddress = new MailAddress(recipientEmail, "MY CLIENT NAME");
  
              var smtp = new SmtpClient {
                  Host = EMAIL_HOST,
                  Port = EMAIL_PORT,
                  EnableSsl = EMAIL_SSL,
                  DeliveryMethod = EMAIL_DELIVERY_METHOD,
                  UseDefaultCredentials = EMAIL_DEFAULT_CREDENTIALS,
                  Credentials = new NetworkCredential(fromAddress.Address, EMAIL_PASS,EMAIL_HOST)
              };
              using (var message = new MailMessage(fromAddress, toAddress) {
                  Subject = subject,
                  Body = body,
                  Priority = MailPriority.High
              }) {
                  smtp.Send(message);
              }
          }
  </code></pre>
  
  <p>I have enabled Less Secure Sign-in, and the configuration seems to be fine. What is the problem?</p>