protected void ButPwd_Click(object sender, EventArgs e)
{
string mainconn = ConfigurationManager.ConnectionStrings["AssDatabaseConnectionString"].ConnectionString;
SqlConnection sqlconn = new SqlConnection(mainconn);
string sqlquery = "select UserEmail,UserPassword from [dbo].[User] where UserEmail=@Email";
SqlCommand sqlcomm = new SqlCommand(sqlquery, sqlconn);
sqlcomm.Parameters.AddWithValue("@Email", TxtEmail.Text);
sqlconn.Open();
SqlDataReader sdr = sqlcomm.ExecuteReader();
if(sdr.Read())
{
string username1 = sdr["UserEmail"].ToString();
string password = sdr["UserPassword"].ToString();
MailMessage mm = new MailMessage();
mm.From = new MailAddress("dylanng2019@gmail.com");
mm.Subject = "Your Password is !";
mm.Body = string.Format("Hello : <h1>{0}</h1> is your Email <br /> Your Password is <h1>{1}<h1>",username1,password);
mm.IsBodyHtml = true;
mm.Priority = MailPriority.High;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
NetworkCredential nc = new NetworkCredential();
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
nc.UserName = "dylanng2019@gmail.com";
nc.Password = "XohImNooBHFR0OVvjcYpJ3NgPQ1qq73WKhHvch0VQtg=";
smtp.UseDefaultCredentials = true;
smtp.Credentials = nc;
smtp.Port = 587;
Labmsg.Text = "Your Password has been sent to " + TxtEmail.Text;
Labmsg.ForeColor = Color.Red;
smtp.Send(mm);
}
else
{
Labmsg.Text = TxtEmail.Text + ". This Email is not exist in the database";
Labmsg.ForeColor = Color.Red;
}
}
Asked
Active
Viewed 487 times
0
-
1You cannot send an email to someone without their email address. That's what the error is saying "a recipient must be specified". – CodingYoshi Jan 03 '20 at 04:05
-
but now it appear The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication Required. i had set the EnableSsl to true – Dylan Ng Jan 03 '20 at 04:17
-
See [this answer](https://stackoverflow.com/a/25215834/4228458) and also the link in that address. – CodingYoshi Jan 03 '20 at 04:42
1 Answers
1
mm.To.Add("recipient@address.com"); //Add this line to your code

Backs
- 24,430
- 5
- 58
- 85
-
thanks for your answer, but now it show this error System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication Required – Dylan Ng Jan 03 '20 at 04:02
-
this `smtp.UseDefaultCredentials = true;` probably overrides your credentials you supply. Try it with setting this `false` – Michaël Hompus Jan 03 '20 at 05:49