Question

I have web app(asp.net mvc3, .net 4) and I am trying to implement the email notification service.

Basically, there is a table with a datetime/content and a user to send email to, and when we get to that datetime on table, I want to send out the notification email.

I am not sure how this should be implemented, should there be some kind of background thread that constantly checks the database? I feel that this would be inefficient.

Can you suggest some ways of doing this?

Was it helpful?

Solution

You will need a service or scheduled job that runs on a system somewhere (I've done this before; I had shared hosting, and wrote a small app which I scheduled to run periodically on my home computer). You can either have this process do the notifications for you, or hit an action on your controller, which will trigger them to be sent out.

It seems that having the service query your database and send out the notifications is the most direct route. However, there are a few reasons why an action in your MVC application might be more appropriate, such as not having remote access to the database or SMTP server.

You can schedule a job to execute an application (such as a console app, or perhaps CURL) using Windows Task Scheduler or the likes. Or you can use something like Quartz.net to create your own service to execute jobs.

OTHER TIPS

That's not the correct approach. You should create a console application and run it periodically using the built in scheduler task.

As extra reference please take a look to this post from Ayende Rahien

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top