views:

139

answers:

4

Hy,

I have a c# program that sends emails with GMail SMTP server and I want to make a service or something running behind that sends this emails every 5 minutes.

Does anyone have any idea how can I make this with c# and asp.net?

+2  A: 

You may want to look at Quartz.NET - a scheduler for the .NET platform to schedule jobs that send emails through Quartz at regular intervals.

mfloryan
A simple and proven solution.
Patrik
+1  A: 

Websites should be stateless, so implementing a continuous process in ASP.NET is a bad idea. You either need a console app that never quits, or a windows service. An even easier way is to use a scheduler and run a console app. The windows scheduler should be enough to do this.

StephaneT
+2  A: 

Two options that spring to mind:

  1. Write a Windows service. Kick off a timer that triggers every five minutes, and do your work there.

  2. Set up a Windows scheduled task ("Task Scheduler" in Vista/Win7) to trigger every five minutes and launch your application.

I'd tend towards the latter. Windows services are easy to set up, but nothing's simpler than no code at all.

Michael Petrotta
I want to make it programaticaly with C#, no configuration... just a application...
Jeff Norman
@Jeff: well, then, a Windows service might suit you. You could even run a timer from within a plain old application.
Michael Petrotta
Actually I am thinking now that I can make a timer that calls my sending email method every 5 minutes. But when I quit the application it will stop... or?
Jeff Norman
@Jeff: yes, when you quit your application, its timer will stop, and the method will no longer be called.
Michael Petrotta
A: 

That's a very broad question—this article might help you out.

Mark B