Click here to Skip to main content
15,884,083 members
Articles / Web Development / ASP.NET
Article

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

Rate me:
Please Sign up or sign in to vote.
3.76/5 (30 votes)
2 Jan 2010CPOL 100.6K   4.7K   44   28
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<o:p>
  • Send the message at daily, weekly, monthly or yearly intervals.<o:p>  
  For this, we normally used windows services or windows application.<o:p>

  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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
India India
Hi, I am Samrat Banerjee from India.
I am a Software Engineer working in .net platform.
I love to explore new technologies.

Comments and Discussions

 
GeneralBad solution Pin
Puchko Vasili2-Jan-10 8:26
Puchko Vasili2-Jan-10 8:26 
GeneralRe: Bad solution Pin
Spunkybabe2-Aug-11 23:53
Spunkybabe2-Aug-11 23:53 
GeneralNeeds some meat Pin
Axel Rietschin2-Jan-10 7:21
professionalAxel Rietschin2-Jan-10 7:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.