title: The server response was: 5.7.0 Authentication Required. Learn more at
body: <p>I tried to run this code and it shows this error.This is reset password where user is required to insert the email address. When the email address is valid, the admin will send the link to the user to do resetting password.  <a href="https://i.stack.imgur.com/E7i3x.png" rel="noreferrer"><img src="https://i.stack.imgur.com/E7i3x.png" alt="enter image description here"></a></p>
  
  <pre><code>    protected void btnResetPwd_Click(object sender, EventArgs e)
      {
          string emailAddress = txtEmail.Text;
  
          User u = db.Users.Single(x =&gt; x.EmailAddress == emailAddress);
  
  
          if (u != null)
          {
              lblMessage.ForeColor = System.Drawing.Color.LimeGreen;
              MailMessage mailMessage = new MailMessage();
  
              StringBuilder sbEmailBody = new StringBuilder();
              sbEmailBody.Append("Dear " + u.Name + ",&lt;br/&gt;&lt;br/&gt;");
              sbEmailBody.Append("Please click on the following link to reset your password");
              sbEmailBody.Append("&lt;br/&gt;"); sbEmailBody.Append("http://localhost/Assignment/Registration/ChangePwd.aspx?uid=" +u.Id);
              sbEmailBody.Append("&lt;br/&gt;&lt;br/&gt;");
              sbEmailBody.Append("&lt;b&gt;Pragim Technologies&lt;/b&gt;");
  
              mailMessage.IsBodyHtml = true;
  
              mailMessage.Body = sbEmailBody.ToString();
              mailMessage.Subject = "Reset Your Password";
              SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);
  
              smtpClient.Credentials = new System.Net.NetworkCredential()
              {
                  UserName = "YourEmail@gmail.com",
                  Password = "YourPassword"
              };
              string to = u.EmailAddress;
              string from = "potato@gmail.com";
  
              smtpClient.EnableSsl = true;
  
              mailMessage.From = new MailAddress(from);
              mailMessage.To.Add(to);
              smtpClient.Send(mailMessage);
              smtpClient.UseDefaultCredentials = false;
  
              lblMessage.Text = "An email with instructions to reset your password is sent to your registered email";
  
  
          }
          else
          {
              lblMessage.ForeColor = System.Drawing.Color.Red;
              lblMessage.Text = "Email Address not found!";
          }
  
      }
  </code></pre>
  
  <p>And this is my web.config</p>
  
  <pre><code>        &lt;system.net&gt;
          &lt;mailSettings&gt;
          &lt;smtp from="Admin &amp;lt;potato@gmail.com&amp;gt;"&gt;
          &lt;network host="smt.gmail.com"
                   port="587"
               enableSsl="true"
               userName="potato@gmail.com"
               password="password"/&gt;
                &lt;/smtp&gt;
               &lt;/mailSettings&gt;
               &lt;/system.net&gt;
  </code></pre>