Hi,
In my application im trying to send emails to different clients when datesubmitted by 8/28/2014 and check after 7 days I want send emails with message.but In database table datesubmitted column has dates from 2011 but I don't want 2011 ,12,13,14 but with recent dates from 2014 .I want to compare with todays date and send mail to particular client.In the below code it is giing days between dates its not comparing.
static void Main(string[] args) { string connectString = ConfigurationSettings.AppSettings["abcdb"]; // SqlConnection conn = new SqlConnection(connectString); // conn.Open(); //SELECT DATEDIFF(DAY, '8/1/2014', getDate()) string sqlStatement = "select DateSubmitted,Status,PONumber from TroubleTicks where ClientID=1"; //SqlCommand cmd = new SqlCommand(str,conn); //SqlDataReader dr = new SqlDataReader(conn,cmd); DateTime originalDate,orderdate; DateTime endDate = DateTime.Today; int totalDays = 0; string ponum, status; //if (dr.Read()) //{ // originalDate =Convert.ToDateTime ( dr["DateSubmitted"]); //} using (SqlConnection conn = new SqlConnection(connectString)) using(SqlCommand cmd = new SqlCommand(sqlStatement, conn)) { conn.Open (); using (SqlDataReader dr = cmd.ExecuteReader()) { while(dr.HasRows ) { while (dr.Read()) { originalDate = Convert.ToDateTime(dr["DateSubmitted"]); ponum =dr["PONumber"].ToString(); status =dr["Status"].ToString (); //TimeSpan leadTime = originalDate.Subtract(DateTime.Today); //if (leadTime.Days <7) // Console.WriteLine("date:" + leadTime); //Console.WriteLine("date:" + status ); while (originalDate <= endDate) { if (originalDate.DayOfWeek == DayOfWeek.Saturday || originalDate.DayOfWeek == DayOfWeek.Sunday) { originalDate = originalDate.AddDays(1); continue; } originalDate = originalDate.AddDays(1); totalDays++; } Console.WriteLine("date:" + totalDays + ponum); Console.ReadLine(); // Console.ReadKey(); //read here } dr.NextResult(); } } } Console.WriteLine("Mail To"); MailAddress to = new MailAddress(Console.ReadLine());
// want to send 3 different ID's Console.WriteLine("Mail From"); MailAddress from = new MailAddress(Console.ReadLine());//in the webapplication submittedby related clientIDName for ClientID=1 ClientName="Argen" MailMessage mail = new MailMessage(from, to); Console.WriteLine("Subject"); mail.Subject = Console.ReadLine(); Console.WriteLine("Your Message"); mail.Body = Console.ReadLine();//want to show Status,PONumber SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; //rtnow im using gmail host
but on the server its different in the webapplication different credentials its working for another application smtp.Port = 587; smtp.Credentials = new NetworkCredential( "example@gmail.com", "example"); smtp.EnableSsl = true; Console.WriteLine("Sending email..."); smtp.Send(mail); }