samedi 22 avril 2017

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.

this is my reset password code. I have not given the file. I am also adding a image of the error. password in web config file . image of the error any help any one?

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Net.Mail;
    using System.Text;
    using System.Data.SqlClient;
    using System.Configuration;
    using System.Data;
    using System.Drawing;



    public partial class ResetPassword_resetpassword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string CS = ConfigurationManager.ConnectionStrings["RegisterDataConnectionString"].ConnectionString;
            using (SqlConnection con = new SqlConnection(CS))
            {
                SqlCommand cmd = new SqlCommand("select * from userDataTable where email='"+TextBox1.Text+"'",con);



                con.Open();

                SqlDataAdapter sda = new SqlDataAdapter(cmd);
                DataTable dt = new DataTable();
                sda.Fill(dt);

                if(dt.Rows.Count != 0)
                {
                    string myGUID =Guid.NewGuid().ToString();
                    int Uid = Convert.ToInt32(dt.Rows[0][0]);
                    SqlCommand cmd1 = new SqlCommand("insert into tblResetPasswordRequests values('"+myGUID+"','"+Uid+"',getdate())",con);
                    cmd1.ExecuteNonQuery();

                    string ToEmailAddress = dt.Rows[0][3].ToString();
                    string Username = dt.Rows[0][1].ToString();
                    string EmailBody = "hi "+Username+" <br/> click the link below to reset your password <br/>http://localhost/IISvirtualDirectory/mainProject/ResetPassword/changePassword.aspx?Uid="+myGUID ;
                    MailMessage PassRecMail = new MailMessage("mananchakma45@gmail.com",ToEmailAddress);
                    PassRecMail.Body = EmailBody;
                    PassRecMail.IsBodyHtml = true;
                    PassRecMail.Subject = "Reset Password";


                    SmtpClient smtpClient = new SmtpClient();

                    smtpClient.Send(PassRecMail);

                }
                else
                {
                    Label1.Text = "There is no valid email ";
                }
            }
        }



    }

this one is my web.config setting , though i have not given the password

  <appSettings>
    <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
    <add key="SendEmail" value="true" />
  </appSettings>



  <system.net>
    <mailSettings>
      <smtp from="mananchakma45@gmail.com">
        <network host="smtp.gmail.com"
         port="587"
         userName="mananchakma45@gmail.com"
         password=""
         enableSsl="true"/>
      </smtp>
    </mailSettings>
  </system.net>

</configuration>




Aucun commentaire:

Enregistrer un commentaire