asp.net - send mail everyday at 8pm using windows services -
below code sending mail service every 3 minutes. want send mail service 1 time in every day @ 8pm. how set in below code.
i'm new windows services help me. i'm using visual studio 2010
public partial class scheduler : servicebase { system.timers.timer createordertimer; private timer timer1 = null; public scheduler() { initializecomponent(); } protected override void onstart(string[] args) { system.timers.elapsedeventhandler(this.timer1_tick); 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 , 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 entered venkat world!!!"; msg.from = new mailaddress("from@gmail.com"); // email id smtpclient client = new smtpclient("smtp.gmail.com", 587); client.credentials = cred; client.enablessl = true; client.send(msg); } }
have @ next library: http://www.quartz-scheduler.net/
with can schedule tasks easely.
you can find examples here on stackoverflow, i.e.
http://stackoverflow.com/a/13567372/849507 http://stackoverflow.com/a/26595446/849507 asp.net vs2010-express
No comments:
Post a Comment