Click here to Skip to main content
15,902,445 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
i want to send a email on particular date in my application.....

how to set timer for that?


XML
lbldate.Text = datetime mydate.Tostring();

public void emailSend()
   {
       DataTable dtemplogin = new DataTable();
       dtemplogin = _login.SelectEmpLogin();
       DataTable dtptIns = new DataTable();
       dtptIns = _login.selectPatientInsurance();


       Connection.DataSource = ConfigurationManager.AppSettings["DataSource"].ToString();
       Connection.Uid = ConfigurationManager.AppSettings["uid"].ToString();
       Connection.Pwd = ConfigurationManager.AppSettings["pwd"].ToString();
       Connection.Initialcatalog = ConfigurationManager.AppSettings["InitialCatalog"].ToString();

       MailMsg.mailSend();
       MailMsg.CcAddress = string.Empty;
       MailMsg.BccAddress = string.Empty;
       MailMsg.Attachments = null;
       MailMsg.Subject = "insurance Expiry alert message";
       MailMsg.FromAddress = "radha@rediffmail.com";
       MailMsg.ToAddress = txtEmailID.Text;
       MailMsg.Password = "hhahshd";
       MailMsg.MessageBody += "<html>";
       MailMsg.MessageBody += "<head>";
       MailMsg.MessageBody += "<title>Insurance is going To expiry on:</title>";
       MailMsg.MessageBody += "</head>";
       MailMsg.MessageBody += "<body>";
       MailMsg.MessageBody += dtptIns.Rows[1]["F_Name"].ToString();
       MailMsg.MessageBody += dtptIns.Rows[5]["Ins_Name"].ToString();
       MailMsg.MessageBody += dtptIns.Rows[6]["Effective_Date_From"].ToString();
       MailMsg.MessageBody += dtptIns.Rows[7]["Effective_Date_To"].ToString();
       MailMsg.MessageBody += "</body>";
       MailMsg.MessageBody += "</html>";

   }


in label i have my date when the emailsend function want to call..
for that how to set timer
Posted
Updated 19-Sep-11 19:41pm
v3

1) Your application must be running continuously for this to work ie you must have a windows service etc.

2) Save your dates to a file or a database.

3) Create a Thread which sleeps every 1 sec and checks if the dates have been passed, if so execute the emailsend method.
 
Share this answer
 
It might help you,

Timer in C#[^]

Timer Class[^]

:)
 
Share this answer
 
In the timer tick event, check the required date and time ,
If its(checking value) value is true
then call the Email send method..
 
Share this answer
 
Hi
To run an application at a particular time..
As Mehdi Gholam said the application must run continuously or you have to make a service that calls send email program at certain time.

Or

Dont include timer in your program and using windows task scheduler call your program to send email.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900