I'd like to integrate an email notification system into my MVC3 application. So when a users tasks are due, they get an email reminder. I'm new to MVC so I'd like to be pointed in the right direction of how to go about this.
Many thanks, Dale
I'd like to integrate an email notification system into my MVC3 application. So when a users tasks are due, they get an email reminder. I'm new to MVC so I'd like to be pointed in the right direction of how to go about this.
Many thanks, Dale
I'm a big fan of using Quartz to execute such background processes. It can be hosted in a windows service or within ASP.NET.
Aside from sending the email you would also need to store when the notification was send to avoid sending duplicate notifications.
It sounds to me like you are looking for an email to get sent out as a deadline approaches, and not have to rely on a user action to trigger the email. For this to happen, you need to have some sort of external process that can check at regular intervals and send emails as needed.
There are multiple ways to set this up, but for a web app, one of my favorite is to have a script or a service that runs in the background that just hits a page of the web-app on a timer. That page is then responsible for checking the database and sending out any emails that need to be sent. You can also do fun things to make sure this process isn't taxing the core features of the MVC app too much by building in rate-limiting features. (This is what FogBugz does, I believe, to process through a queue of emails that need to be sent or ingested in a way that doesn't slow down the user)
Other ways to do this are basically the same pattern, but the logic of when to send emails and actually sending the emails gets shifted out of the MVC app and into the external process.
As far as how to send the actual emails, a quick Google search on how to send emails from .Net (assuming you are talking about ASP.Net MVC3) will give you much better information on how to go about sending an email than I can.
I would start by getting comfortable with the concepts of Dependency Injection and then develop the code that sends notifications as a generic module.
The actual notification engine doesn't need to know anything about your application, or what triggers emails, you should be able to build (or use) something that simply sends messages to a group of recipients (you can determine how functional this component will be, but it cannot bleed into the logic of your underlying application).
Once it has been tested and you are confident it does what it needs too, you can simply inject into your mvc application as required. This way your application's controllers will perform the necessary application logic, using your notification service as required.
Ideally your MVC app shouldn't contain much business logic at all, it should simply contain references to a bunch of different services that perform the logic of your app, and your controller should simply know how to use the services appropriately.