C # code
Protected override void onstart (string [] ARGs)
{
Mytimer ();
}
// instantiate system. timers. timer
private void mytimer ()
{< br> // set the time interval
system. timers. timer Mt = new system. timers. timer (Int. parse (configresource. interval) * 60*1000);
Mt. elapsed + = new system. timers. elapsedeventhandler (mtimedevent);
Mt. enabled = true;
}
// Construct the system. Timers. Timer instance interval event (scheduled execution event)
Private void mtimedevent (Object source, system. Timers. elapsedeventargs E)
{
// Start work
Startwork ();
}
Public void startwork ()
{
// Query the time in Table A from the database Code Omitted...
// Time comparison
If (...) // The time is later than the current system time
{
// Send an email
Int istatus = Sendmail ("Your specified recipient email address", "title", "content ");
If (istatus> 0)
{
Using (streamwriter Sw = new streamwriter (filepath + "log.txt", system. Text. encoding. getencoding ("UTF-8 ")))
{
Sw. wirte (system. datetime. Now. tostring () + "sent successfully! ")
}
}
Else {// Failed}
}
}
/// <Summary>
/// Send email
/// </Summary>
/// <Param name = "srecipientemail"> recipient address </param>
/// <Param name = "ssubject"> topic </param>
/// <Param name = "smessage"> content </param>
/// <Returns> whether the message is sent successfully </returns>
Public bool Sendmail (string srecipientemail, string ssubject, string smessage)
{
// Email object
Mailmessage emailmessage;
// SMTP client object
Smtpclient client;
// Initialize the email object
String ssenderemail = "your mailbox ";
Emailmessage = new mailmessage (ssenderemail, srecipientemail, ssubject, smessage );
Emailmessage. isbodyhtml = true;
Emailmessage. subjectencoding = system. Text. encoding. default;
Emailmessage. bodyencoding = system. Text. encoding. default;
// Add
Emailmessage. headers. Add ("X-priority", "3 ");
Emailmessage. headers. Add ("X-msmail-priority", "normal ");
Emailmessage. headers. Add ("X-mailer", "Microsoft Outlook Express 6.00.2900.2869 ");
Emailmessage. headers. Add ("X-mimeole", "produced by Microsoft mimeole v6.00.2900.2869 ");
// Email sending client
Client = new smtpclient ();
// Email server and account information
Client. Host = "email server ";
// Client. Host = "smtp.163.com ";
// Client. Port = 465;
// Client. enablessl = true;
System. net. networkcredential credential = new system. net. networkcredential ();
Credential. Username = "your email account" // you can configure it in the resource file.
Credential. Password = "password"
Client. Credentials = credential;
Try
{
Client. Send (emailmessage );
}
Catch (exception E)
{
Return false;
}
Return true;
}