The server response was: 5.7.0 Authentication Required. Learn more at

19,138

Solution 1

It would appear that nothing is wrong with your code, but that gmail is not set up correctly.

As a start, I would try changing the settings of your gmail account to use "Less Secure App Access" - see https://myaccount.google.com/lesssecureapps and see if this works.

If this works, then you can try perhaps accessing gmail in a more secure way - perhaps enabling 2 factor authentication and using app passwords - see https://support.google.com/accounts/answer/185833?hl=en

Solution 2

Also it could be related with weakness of your password. Don't mind if there is writing STRONG while picking a password. Pick a password as complicated as possible if it contains numbers like 123 it could cause problem.

Because this potentially makes your account less secure, you'll need to update your password to include a minimum of 8 characters, a mixture of letters and numbers, and at least one special character (e.g., @, !, #, etc.). Your SMTP settings may not work if your password doesn't meet these requirements.

https://support.mindbodyonline.com/s/article/204253056-SMTP-errors-What-does-it-mean?language=en_US#:~:text=The%20SMTP%20server%20requires%20a,Yes%22%20in%20your%20SMTP%20settings.

Share:
19,138

Related videos on Youtube

How To Game
Author by

How To Game

Updated on June 04, 2022

Comments

  • How To Game
    How To Game almost 2 years

    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. enter image description here

        protected void btnResetPwd_Click(object sender, EventArgs e)
        {
            string emailAddress = txtEmail.Text;
    
            User u = db.Users.Single(x => 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 + ",<br/><br/>");
                sbEmailBody.Append("Please click on the following link to reset your password");
                sbEmailBody.Append("<br/>"); sbEmailBody.Append("http://localhost/Assignment/Registration/ChangePwd.aspx?uid=" +u.Id);
                sbEmailBody.Append("<br/><br/>");
                sbEmailBody.Append("<b>Pragim Technologies</b>");
    
                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 = "[email protected]",
                    Password = "YourPassword"
                };
                string to = u.EmailAddress;
                string from = "[email protected]";
    
                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!";
            }
    
        }
    

    And this is my web.config

            <system.net>
            <mailSettings>
            <smtp from="Admin &lt;[email protected]&gt;">
            <network host="smt.gmail.com"
                     port="587"
                 enableSsl="true"
                 userName="[email protected]"
                 password="password"/>
                  </smtp>
                 </mailSettings>
                 </system.net>
    
  • EvenThis
    EvenThis over 3 years
    Thanks! This is exactly what I was missing!