title: 'The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication Required
body: <p>System.Net.Mail.SmtpException: 'The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication Required.</p>
  
  <p><a href="https://i.stack.imgur.com/w1ObP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/w1ObP.png" alt="enter image description here"></a></p>
  
  <pre><code>        using (SqlConnection con = new SqlConnection(ApplicationSettings.ConnectionString()))
          {
              con.Open();
              //try
              //{
                  SqlCommand cmd = new SqlCommand("SELECT [Email Address] FROM [Staff] WHERE [Access Level]='Manager'", con);
                  SqlDataReader sdr = cmd.ExecuteReader();
                  if (sdr.Read())
                  {
  
                      string emailaddress = Convert.ToString(sdr["Email Address"]);
  
  
                      MailMessage mail = new MailMessage();
                      SmtpClient smtpServer = new SmtpClient("smtp.gmail.com");
                      mail.From = new MailAddress("possystemmahdealjamil@gmail.com");
                      mail.To.Add(emailaddress);
                      mail.Subject = "Todays POS System Reports";
                      mail.Body = "Todays shift is closed at"+DateTime.Now.ToString();
  
                      smtpServer.Port = 587;
                      smtpServer.Credentials = new [enter image description here][1]System.Net.NetworkCredential("possystemmahdealjamil@gmail.com", @"###########");
                      smtpServer.EnableSsl = true;
                      smtpServer.Send(mail);
  
                      MessageBox.Show("Mail is Send Successfully ", "Successful", MessageBoxButtons.OK, MessageBoxIcon.Information);
                  }
              //}
              //catch (Exception ex)
              //{
              //    MessageBox.Show(ex.Message, "open shift failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
              //}
              //finally
              //{
              //    con.Close();
              //}
          }
  </code></pre>