本文介绍了服务器响应为:5.7.0需要身份验证.了解更多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图运行此代码,它显示此错误.这是重置密码,要求用户插入电子邮件地址.当电子邮件地址有效时,管理员会将链接发送给用户以重置密码.

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.

    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!";
        }

    }

这是我的web.config

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>

推荐答案

您的代码似乎没有问题,但是gmail设置不正确.

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

首先,我会尝试将您的gmail帐户的设置更改为使用缺少安全的应用程序访问权限"-请参阅https://myaccount.google.com/lesssecureapps ,看看是否可行.

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.

如果这行得通,那么您可以尝试以更安全的方式访问gmail-也许启用2因子身份验证并使用应用密码-请参见 https://support.google.com/accounts/answer/185833?hl=zh_CN

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

这篇关于服务器响应为:5.7.0需要身份验证.了解更多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 01:41