samedi 20 juin 2015

code execute but not reviving mail in inbox c#

i have write code for sending email but code executes succefull but mail is not receiving inbox.plzz help me and correct code where is mistake or why not receiving mail.below of my code see my code and tell me what is problem that is not sending mail. i m working on project in which forget password and username send to user who enter email ID.

protected void Button2_Click(object sender, EventArgs e) {

        string email = TextBox1.Text;
        SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=regester;Integrated Security=True");
        string command = "select id,password,email from reg ";
        SqlCommand sqlcmd = new SqlCommand(command, con);
        //sqlcmd.Parameters["@Email"].Value = email;
        //sqlcmd.Parameters.Add("@Email", email);
        if (con.State == ConnectionState.Open)
            SqlDataReader dtr = sqlcmd.ExecuteReader();

            while (dtr.Read())
                if (dtr[2].ToString().Equals(TextBox1.Text))
                    MailMessage mail = new MailMessage();
                    mail.From = new MailAddress("");
                    mail.Subject = "Your userId and Password";
                    mail.Body = "Your<br/> UserId:<b>" + dtr[0].ToString() + "</b><br/>" + "Password:<b>" + dtr[1].ToString() + "</b>";
                    mail.IsBodyHtml = true;
                    SmtpClient smtp = new SmtpClient();
                    smtp.Host = "";
                    smtp.Port = 587;

                    smtp.Credentials = new System.Net.NetworkCredential("your id", "your password");
                    smtp.EnableSsl = true;
                    //smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                    //smtp.EnableSsl = true;
                    //smtp.UseDefaultCredentials = true;
                    smtp.EnableSsl = true; //Gmail works on Server Secured Layer
                    catch (Exception ex)


                    Label1.Text = "check your mailbox for user iD and Password";

                    string javaScript = "<script language=JavaScript>\n" + "alert('User Id and password send to Your mail box');\n" + "</script>";
                    RegisterStartupScript("xyz", javaScript);
                    Label1.Text = "Email Id not valid";


Aucun commentaire:

Enregistrer un commentaire