I am developing a winforms/database software. It is a software that will be used by everyone in the office, using the same database. There is a column which holds "datetime" of a task. Also there is a delay time for this task, what I want to do is, program should trigger sendMail()
function if today's date is bigger than datetime + delaytime
. How can I trigger this function, it should be user-independent?
void sendMail(string taskid, string subject, string message)
{
try
{
SqlCommand komut = new SqlCommand();
komut.CommandText = "select planner from db_owner.tbl_SpecificTask where TASKID = @taskid";
komut.Parameters.AddWithValue("@taskid", TASKID);
komut.Connection = Db.Db;
komut.CommandType = CommandType.Text;
SqlDataReader dr = komut.ExecuteReader();
while (dr.Read())
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient();
mail.To.Add(dr[0].ToString());
//mail.To.Add(dr[1].ToString());
mail.From = new MailAddress("task.notification@tr.companyA.com");
mail.Subject = subject;
mail.IsBodyHtml = true;
mail.Body = message;
SmtpServer.Host = "hiddeninfo";
SmtpServer.Port = hiddeninfo;
SmtpServer.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
try
{
SmtpServer.Send(mail);
}
catch (Exception ex)
{
Debug.WriteLine("Exception Message: " + ex.Message);
if (ex.InnerException != null)
Debug.WriteLine("Exception Inner: " + ex.InnerException);
}
}
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex);
}
finally
{
Db.Close();
}
}