Click here to Skip to main content
15,355,133 members
Articles / Web Development / ASP.NET
Article
Posted 2 Jan 2010

Stats

94.2K views
4.7K downloads
44 bookmarked

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
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)

Share

About the Author

Samrat Banerjee
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

 
QuestionSend Email at Specific Time ??? Pin
Member 1075879012-Nov-17 21:45
MemberMember 1075879012-Nov-17 21:45 
QuestionHow many times it's send mail to user Pin
PallavSingh27-Jul-16 23:02
professionalPallavSingh27-Jul-16 23:02 
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
Hemant Singh Rautela29-Dec-12 2:55
professionalHemant Singh Rautela29-Dec-12 2:55 
GeneralMy vote of 1 Pin
bbirajdar21-Nov-12 2:12
Memberbbirajdar21-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
tanweer29-Jun-12 0:33
Membertanweer29-Jun-12 0:33 
GeneralMy vote of 5 Pin
Kolli Hari Chowdary13-Jun-12 22:56
MemberKolli Hari 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
Sharma Richa8-Nov-11 1:35
MemberSharma Richa8-Nov-11 1:35 
QuestionNot Working Pin
Technoses8-Oct-11 1:31
MemberTechnoses8-Oct-11 1:31 
Sigh | :sigh: Not working on IIS7
please help
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
Talking Dotnet3-Jan-10 22:55
MemberTalking Dotnet3-Jan-10 22:55 
GeneralThanks but ! Pin
Tarik Guney2-Jan-10 13:10
MemberTarik Guney2-Jan-10 13:10 
GeneralRe: Thanks but ! Pin
Venkata Aditya Korada13-Sep-12 14:27
MemberVenkata Aditya Korada13-Sep-12 14:27 

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.