title: Server does not support secure connections in C#
body: <p>I'm getting the error "Server does not support secure connections" with my code below.</p>
  
  <pre><code>            SmtpClient smtp = new SmtpClient();
              MailMessage mail = new MailMessage();
              mail.From = new MailAddress("*****@gmail.com");
              mail.To.Add(recieverId);
              mail.Subject = "Invoice Copy and Delivery Confirmation for booksap.com Order " + orderno + ". Please Share Feedback.";
              System.Net.Mail.Attachment attachment;
              attachment = new System.Net.Mail.Attachment(Server.MapPath("OrderMail\\Invoice.pdf"));
              mail.Attachments.Add(attachment);
              MailBody = "We are pleased to inform that the following items in your order " + orderno + " have been placed. This completes your order. Thank you for shopping! ";
              StreamReader reader = new StreamReader(Server.MapPath("~/MailHTMLPage.htm"));
              string readFile = reader.ReadToEnd();
              string myString = "";
              myString = readFile;
              myString = myString.Replace("$$Name$$", ContactPersonName);
              myString = myString.Replace("$$MailBody$$", MailBody);
              mail.Body = myString.ToString();
              mail.IsBodyHtml = true;
              mail.Priority = MailPriority.High;
              smtp.Host = "smtp.gmail.com";
              smtp.EnableSsl = true;
              smtp.UseDefaultCredentials = true;
              smtp.Port = 587;
              smtp.Credentials = new System.Net.NetworkCredential("*******@gmail.com", "*******");
              smtp.Send(mail);
              mail.Dispose();
              mail = null;
  </code></pre>
  
  <p>How can I fix this issue?
  If I set</p>
  
  <pre><code> EnabledSsl = false
  </code></pre>
  
  <p>it will return the error: <strong>The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Client was not authenticated.</strong></p>