Click here to Skip to main content
Click here to Skip to main content

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

, 2 Jan 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Samrat Banerjee
Software Developer (Senior) Viscus Infotech Ltd. [India]
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

 
QuestionSame code but dosnt work Pinmembervezo1124-Jun-14 5:21 
QuestionMessage Removed Pinmembervezo1122-Jun-14 8:39 
QuestionVery Nice article ...... Pinmemberheemanshubhalla15-Feb-14 7:01 
AnswerRe: Very Nice article ...... PinmemberSamrat Banerjee28-Feb-14 23:42 
Question[My vote of 1] its not working i have tested on my shared hosting Pinmembersamiatcodeproject17-Sep-13 2:09 
GeneralMy vote of 5 PinmemberMember 97250353-Jul-13 23:35 
QuestionHow to send mail at specific time? PinmemberChanchal Purbia3-Mar-13 20:57 
You article is very nice.....
Is it possible to send email at specific time (eg. 12:01 am) without using windows service???
Mail to be send contains data from database...
if u know solution, plz help....
GeneralMy vote of 1 Pinmemberhemantrautela29-Dec-12 2:55 
GeneralMy vote of 1 Pinmemberaspnet_regiis -i21-Nov-12 2:12 
GeneralMy vote of 5 Pinmemberjayantj13-Oct-12 3:20 

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

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

| Advertise | Privacy | Mobile
Web04 | 2.8.141029.1 | Last Updated 2 Jan 2010
Article Copyright 2010 by Samrat Banerjee
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid