Reputation:
i am creating a webapp in which i need to fire a web service in every 12/24 hours
here is my stored procedure
alter proc TMSautomail
@datefrm datetime,
@dateto datetime
as
begin
select email,UserName from tblUser where
UserName not in(select UserName from userlogin
where date between @datefrm and @dateto)
end
i am getting the email id from here
[WebMethod]
public void fireautomail()
{
string email = "";
string empname = "";
DateTime datefrm = DateTime.Today;
DateTime dateto = DateTime.Today.AddDays(1);
MailMessage msg = new MailMessage();
string mailfrom = "testemail";
cmd = new SqlCommand("TMSautomail");
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = con;
con.Open();
cmd.Parameters.AddWithValue("@datefrm",datefrm);
cmd.Parameters.AddWithValue("@dateto", dateto);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
for(int i=0; i<ds.Tables[0].Rows.Count;i++)
{
empname = ds.Tables[0].Rows[i][1].ToString();
email = ds.Tables[0].Rows[i][1].ToString();
}
if (email != "" && email.Length != 0 && email != "NULL")
{
msg.From = new MailAddress(mailfrom);
string subject = "Login Details";
msg.Subject = subject.ToString();
msg.IsBodyHtml = true;
var password = "testpassword";
msg.Body = "<b style='color:red'>Dear " + empname + "</b><br /><br />"
+ "You Forget To Logged In Today<br/>"
+ " You May Miss Important Task's <br/>"
+ " Login To Be Updated <br/>"
+ "Regards<br/>"
+ "Team DES.";
SmtpClient sc = new SmtpClient("smtp.gmail.com");
sc.Port = 587;
sc.Credentials = new NetworkCredential(mailfrom, password.ToString());
sc.EnableSsl = true;
sc.Send(msg);
string edetails = "";
edetails = edetails + " " + "success";
}
}
and this is my web service web method,
here i have date of today and tomorrow which will validate and fetch data from storedprocedure, but the problem is,
i want to fire this web service periodically, like daily at 6pm and 10am
what i need to do in this web service?
Upvotes: 0
Views: 99
Reputation: 314
You can trigger a particular task periodically using windows task scheduler. Go to windows "start" type -> "task scheduler", then create a new task and configure it with what you want this job to do, for example this is how you trigger a JAVA code: Create a .cmd file in some location with content "C:\Program Files\Java\jdk1.8.0_25\bin\java.exe" -jar "E:\YourProgram.jar"
Now tell the task scheduler to run this .cmd file and give the time period when to call this .cmd which inturn calls your java program which has the business logic of your triggering the mails or whatever. (your java program can simply have just a main() function) similar to main in c#
Upvotes: 1