Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Schedule Email Through ASP.NET or Schedule Tasks Using ASP.NET

0.00/5 (No votes)
2 Jan 2010 1  
Send schedule(automatic) emails through ASP.NET web application.

Introduction

 In many web application we need to send schedule(automatic) emails and we schedule them.
 like:

  • Sends emails on a regular basis
  • Send the message at daily, weekly, monthly or yearly intervals.  
  For this, we normally used windows services or windows application.

  But in a shared host environment you're out of luck for running these kind of application because you  don't  have access on a shared server.

Background 

We can perform scheduled job process through our ASP.NET web projects without buying dedicated servers.

Advantage:
1. No need to buying dedicated servers.
2. Perform scheduled job process through our ASP.NET web application. 

Using the code 

As we know the web server IIS is continuously running, we can add a timer in the application and the timer can manage all these activities.   

		
    // Inside Global.ascx 
    void Application_Start(object sender, EventArgs e) 
    {
        // Code that runs on application startup
        System.Timers.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)
    {
        // use your mailer code 
        clsScheduleMail objScheduleMail = new clsScheduleMail();
        objScheduleMail.SendScheduleMail();   
    }
   // inside your class
    public void SendScheduleMail()
    { 
      // Write your send mail code here.
    } 
For more details, please refer to the uploaded code.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here