[英]A recipient must be specified. I encounter this error when I want to use ASP.NET to send email
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;
}
}
mm.To.Add("recipient@address.com"); //Add this line to your code
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.