Last post Aug 29, 2019 10:29 AM by AddWeb Solution
Aug 28, 2019 01:18 PM|jonnygareth30|LINK
I am trying to setup an automated email to be sent on a daily or weekly basis by using just ASP.NET C#. Please see below the code I have so far.
void Application_Start(object sender, EventArgs e)
// Code that runs on application startup
Timer myTimer = new System.Timers.Timer();
// Set the Interval to 5 seconds (5000 milliseconds).
myTimer.Interval = 5000;
myTimer.AutoReset = true;
myTimer.Elapsed += new ElapsedEventHandler(myTimer_Elapsed);
myTimer.Enabled = true;
public void myTimer_Elapsed(object source, System.Timers.ElapsedEventArgs e)
clsScheduleMail objScheduleMail = new clsScheduleMail();
public class clsScheduleMail
public void SendScheduleMail()
The details I would like to send are stored within a GridView on a separate page, please see below code:
private void BindGrid()
using (var commandhol = con.CreateCommand())
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand("Docs", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@ID", SqlDbType.VarChar).Value = ID;
using (var commandeh = con.CreateCommand())
DataTable dta = new DataTable();
SqlCommand myCmdeh = new SqlCommand("Portal_HS_ExpiringDocs", con);
myCmdeh.CommandType = CommandType.StoredProcedure;
SqlDataAdapter daeh = new SqlDataAdapter(myCmdeh);
myCmdeh.Parameters.Add("@ID", SqlDbType.VarChar).Value = ID;
GV.DataSource = dta;
I would like to populate the automated email with the information from the GridView (GV) but I am not sure how I will be able to do this?
Any help would be greatly appreciated.
Many thanks in advance
Aug 28, 2019 05:06 PM|mgebhard|LINK
I recommend writing a console application and use Windows task scheduler. SQL server has email and can run schedule code to run too.
Your current approach is a poor design. Your application can spin down due to none use and emails will not be sent. You are using a UI control without any UI. If you must use a web application to schedule a task then look into quartz or one of the many
ASP.NET task schedulers. Just Google...
If you pay for hosting, hosts generally have a scheduled task feature. Ask your host for assistance.
Aug 29, 2019 10:29 AM|AddWeb Solution|LINK
yes you can do. please refer below links.