title: Error when sending an email c#
body: <p>I try to send an email (with gmail) in C#. I check the solutions I can find on google but it never works for me, I always have the error : </p>
  
  <blockquote>
    <p>SMTP server requires a secure connection or the client was not
    authenticated. The response from the server Was: 5.5.1 Authentication
    Required.</p>
  </blockquote>
  
  <p>This is an exampe of code :</p>
  
  <pre><code>string smtpAddress = "smtp.gmail.com";
  int portNumber = 587;
  bool enableSSL = true;
  
  string emailFrom = "*****@gmail.com";
  string password = "*****";
  string emailTo = "******@gmail.com";
  string subject = "Hello";
  string body = "Hello, I'm just writing this to say Hi!";
  
  using (MailMessage mail = new MailMessage())
  {
      mail.From = new MailAddress(emailFrom);
      mail.To.Add(emailTo);
      mail.Subject = subject;
      mail.Body = body;
      mail.IsBodyHtml = true;
  
      using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber))
      {
          smtp.Credentials = new NetworkCredential(emailFrom, password);
          smtp.EnableSsl = enableSSL;
          smtp.Send(mail);
      }
  }
  </code></pre>