Click here to Skip to main content
11,718,016 members (83,486 online)
Click here to Skip to main content

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

, 2 Jan 2010 CPOL 50.8K 3.4K 41
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.

You may also be interested in...

Comments and Discussions

 
QuestionSame code but dosnt work Pin
vezo1124-Jun-14 5:21
membervezo1124-Jun-14 5:21 
QuestionVery Nice article ...... Pin
heemanshubhalla15-Feb-14 7:01
memberheemanshubhalla15-Feb-14 7:01 
AnswerRe: Very Nice article ...... Pin
Samrat Banerjee28-Feb-14 23:42
memberSamrat Banerjee28-Feb-14 23:42 
Question[My vote of 1] its not working i have tested on my shared hosting Pin
samiatcodeproject17-Sep-13 2:09
membersamiatcodeproject17-Sep-13 2:09 
GeneralMy vote of 5 Pin
Member 97250353-Jul-13 23:35
memberMember 97250353-Jul-13 23:35 
QuestionHow to send mail at specific time? Pin
Chanchal Purbia3-Mar-13 20:57
memberChanchal Purbia3-Mar-13 20:57 
GeneralMy vote of 1 Pin
hemantrautela29-Dec-12 2:55
memberhemantrautela29-Dec-12 2:55 
GeneralMy vote of 1 Pin
aspnet_regiis -i21-Nov-12 2:12
memberaspnet_regiis -i21-Nov-12 2:12 
GeneralMy vote of 5 Pin
jayantj13-Oct-12 3:20
memberjayantj13-Oct-12 3:20 
GeneralMy vote of 1 Pin
Member 92790763-Aug-12 5:27
memberMember 92790763-Aug-12 5:27 
GeneralMy vote of 5 Pin
tanweer akhtar29-Jun-12 0:33
membertanweer akhtar29-Jun-12 0:33 
GeneralMy vote of 5 Pin
Hari Chowdary13-Jun-12 22:56
groupHari Chowdary13-Jun-12 22:56 
Questionsend mail on cache item expires in asp.net Pin
pranaysoni007819-May-12 21:03
memberpranaysoni007819-May-12 21:03 
Questionhow to use this class file with database Pin
sathya.spidy1-Apr-12 20:53
membersathya.spidy1-Apr-12 20:53 
AnswerRe: how to use this class file with database Pin
Venkata Aditya Korada7-Sep-12 7:40
memberVenkata Aditya Korada7-Sep-12 7:40 
GeneralMy vote of 4 Pin
Richa.Net8-Nov-11 1:35
memberRicha.Net8-Nov-11 1:35 
QuestionNot Working Pin
Technoses8-Oct-11 1:31
groupTechnoses8-Oct-11 1:31 
GeneralHelp Required Pin
syed_developer31-Jan-10 1:38
membersyed_developer31-Jan-10 1:38 
Generalhttp://msdn.microsoft.com/en-us/library/ms525334.aspx Pin
MoPhat4-Jan-10 1:11
memberMoPhat4-Jan-10 1:11 
GeneralRe: http://msdn.microsoft.com/en-us/library/ms525334.aspx Pin
Member 11626297-Jan-10 17:03
memberMember 11626297-Jan-10 17:03 
GeneralMy vote of 1 Pin
Virendra Dugar3-Jan-10 22:55
memberVirendra Dugar3-Jan-10 22:55 
GeneralThanks but ! Pin
atarikg2-Jan-10 13:10
memberatarikg2-Jan-10 13:10 
GeneralRe: Thanks but ! Pin
Venkata Aditya Korada13-Sep-12 14:27
memberVenkata Aditya Korada13-Sep-12 14:27 
GeneralBad solution Pin
Puchko Vasili2-Jan-10 8:26
memberPuchko Vasili2-Jan-10 8:26 
GeneralRe: Bad solution Pin
Spunkybabe2-Aug-11 23:53
memberSpunkybabe2-Aug-11 23:53 

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 | Terms of Use | Mobile
Web02 | 2.8.150901.1 | Last Updated 2 Jan 2010
Article Copyright 2010 by Samrat Banerjee
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid