public partial class Scheduler : ServiceBase
{
System.Timers.Timer createOrderTimer;
private Timer timer1 = null;
public Scheduler()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
////timer1 = new Timer();
////this.timer1.Interval = 30000;
////this.timer1.Elapsed += new System.Timers.ElapsedEventHandler(this.timer1_Tick);
////timer1.Enabled = true;
////Library.WriteErrorLog("Test Window Service started");
createOrderTimer = new System.Timers.Timer();
createOrderTimer.Elapsed += new System.Timers.ElapsedEventHandler(GetMail);
createOrderTimer.Interval = 180000;
createOrderTimer.Enabled = true;
createOrderTimer.AutoReset = true;
createOrderTimer.Start();
}
private void timer1_Tick(object sender, ElapsedEventArgs e)
{
Library.WriteErrorLog("Timer Ticked and some job has been done successfully");
}
protected override void OnStop()
{
timer1.Enabled = false;
Library.WriteErrorLog("Test Window Service stopped");
}
public void GetMail(object sender, System.Timers.ElapsedEventArgs args)
{
NetworkCredential cred = new NetworkCredential("abc@gmail.com", "abc");
MailMessage msg = new MailMessage();
msg.To.Add("to@abc.com");
msg.Subject = "Welcome Venkat";
msg.Body = "You Have Successfully Entered to venkat World!!!";
msg.From = new MailAddress("from@gmail.com"); // Your Email Id
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
// SmtpClient client1 = new SmtpClient("smtp.mail.yahoo.com", 465);
client.Credentials = cred;
client.EnableSsl = true;
client.Send(msg);
}
}