connection.Open(); OleDbCommand command1 = new OleDbCommand(); command1.Connection = connection; string cq = "Select Email From student where S_ID in(select S_ID FROM studentbook where DateDiff('d',[Issue_Date], NOW())=31) "; command1.CommandText = cq; OleDbDataAdapter da1 = new OleDbDataAdapter(command1); DataTable dt1 = new DataTable(); da1.Fill(dt1); foreach (DataRow row in dt1.Rows) { string email = row["Email"].ToString(); MessageBox.Show("Trying to send email "); using (MailMessage mm = new MailMessage("sujitcsecuet@gmail.com", email)) { mm.Subject = "Attention please,renew your book"; mm.Body = string.Format("1 month over,you should renew or return the book"); mm.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.EnableSsl = true; System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(); credentials.UserName ="xxxxxxx"; credentials.Password = "xxxxxx"; smtp.UseDefaultCredentials = true; smtp.Credentials = credentials; smtp.Port = 587; smtp.Send(mm); MessageBox.Show("Email sent successfully"); } }
smtp.UseDefaultCredentials = false;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)