title: Getting SMTP server connection error while sending mail
body: <p>I am getting a server error while sending email.</p>
  
  <blockquote>
    <p>The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication Required. Learn more at...</p>
  </blockquote>
  
  <pre><code>            MailMessage message = new MailMessage();
              using (var smtp = new SmtpClient())
              {
                  message.From = new MailAddress("email");
                  message.To.Add(new MailAddress(toEmailAddress));
  
                  message.Subject = "Order Confirmation - Bahwan Electronics";
                  message.IsBodyHtml = true; //to make message body as html  
                  message.Body = htmlString;
                  smtp.Port = 587;
                  smtp.Host = "smtp.gmail.com"; //for gmail host  
                  smtp.EnableSsl = true;
                  smtp.UseDefaultCredentials = false;
                  smtp.Credentials = new NetworkCredential("email", "password");
                  smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
  
                  smtp.Send(message);
                  return true;
              }
  </code></pre>
  
  <p>I tried above code it is working fine in Local but when I hosted it in server I am getting above error.
  No two factor auth is enabled in email and also enabled less secure apps.</p>
  
  <p>I am not able to find any solution from the previous questions asked for the same issue.
  And tried all the solutions. It is working on local but after hosting it <em>smtp.Send</em> method throws error.</p>