views:

768

answers:

5

I got the assignment to unify and simplyfy the companies Email sendouts from their site, with the possibility to edit the emails them selves. So Im scetching on a C# Window Form application with WYSIWYG-editor to manage all the emails. The email is stored in SQL-DB

But im in dire need of some tips and pointers on the logic of some of the sendouts.

Some of the sendouts is action triggerd from signups on the site etc. But some sendouts is intervall based, like search-match-email-notification and other reminder-emails wich is sent out in intervals from 5 min to every midnight.

My dilema is this: How do you best handle interval based sendouts? Can you implement some kind of deamon or service the checks stored procedurs at given intervals and trigger sendouts if there is any hits? I would prefer if the Application could handle both the managing of the email content and the schedueled sendouts, (the 5 min checks and every midnight)

Or is there any other smarter way to tackle the interval based sendouts?

Thankfull for tips and pointers on how to tackle this

A: 

Some sort of queue would be ideal for you. you would place your request in the queue and it would get generated. Trigger can place the request in queue as well as your UI. And ofcourse I expect you are doing that through the code (smtp)

Umair Ahmed
A: 

This is a very broad question but if you are using SQL Server you have alot of email options built in. Also Queues and scheduler built in.

76mel
Can you handle the queues and scheduels from the c# code? to add/edit/remove etc
Andreas
@ads81 You can when using the SQL Management Objects libraries available in SQL 2008, and SQLDMO available in any version below
Diago
+1  A: 

Google for "C# windows service" - a service is the Windows equivalent of a daemon, the ideal way to write a program that runs in the background, starts up automatically on a server, and doesn't require the user to log in before it starts.

Make the service Thread.Sleep for a few seconds at a time and check whether it is time to shutdown, or whether to poll the database for emails to send.

http://www.systemnetmail.com/

Daniel Earwicker
+2  A: 

For the sign-up emails you can just add code to send the email to whatever is being executed when users are signing up.

For the scheduled emails there are a couple of ways that you could handle it.

If you think just managing it all in the database is better, and are on SQL 2005 or above, there is built-in Database Mail functionality. http://msdn.microsoft.com/en-us/library/ms175887.aspx
Recurring emails can be sent by scheduled jobs that check a queue of emails that you maintain.

If you want to handle the emails in your code you can use System.Net.Mail. The scheduling can be handled by a Windows Service or a recurring task in the OS.
http://support.microsoft.com/kb/226795

OG
+1  A: 

Try a scheduling engine like http://quartznet.sourceforge.net/

Simon