title: Error while sending mail - The SMTP server requires a secure connection or the client was not authenticated
body: <p>i have tried mostly every example available on net but still no working,whenever i click on submit button it shows this error ,please anyone help me with this</p>
  
  <pre><code> protected void btnsubmit_Click(object sender, ImageClickEventArgs e)
  {
      DAL.s_email = txtforget.Text;
      DataTable dt = new DataTable();
      dt = BAL.forgot_pass(DAL);
      if (dt.Rows.Count &gt; 0)
      {
          System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
          msg.From = new MailAddress("my@email.com");
          msg.To.Add(txtforget.Text);
          msg.Subject = "Yor Password details";
          msg.Body = "Hi,&lt;br&gt;Please check your Login Details&lt;br/&gt;&lt;br/&gt; Your Username : " + dt.Rows[0]["Username"] + "&lt;br/&gt;&lt;br/&gt; Your Password " + dt.Rows[0]["Password"] + "&lt;br/&gt;&lt;br/&gt;";
          msg.IsBodyHtml = true;
          SmtpClient smtp = new SmtpClient();
          smtp.Host = "smtp.gmail.com";
          smtp.Port = 587;
          smtp.EnableSsl = true;
          smtp.UseDefaultCredentials = false;
          smtp.Credentials = new System.Net.NetworkCredential("my@email.com", "****");                       
          smtp.Send(msg);
          Label2.Text = "your username and password is sent";
          txtforget.Text = "";
      }
      else
      {
          Label2.Text = "Email is not registered";
      }
  }
  </code></pre>
  
  <p>web config</p>
  
  <pre><code>&lt;system.net&gt;
      &lt;mailSettings&gt;
          &lt;smtp from="my@email.com"&gt;
              &lt;network host="smtp.gmail.com" password="****" port="587" userName="my@email.com"  defaultCredentials="false" enableSsl="true"/&gt;
          &lt;/smtp&gt;
      &lt;/mailSettings&gt;
  &lt;/system.net&gt;
  </code></pre>