Search code examples
asp.net-mvcemailscheduled-tasksncron

MVC scheduled mail sending


I have got an ASP.NET MVC 4 application, and I want it to send a report e-mail every week. I've read about Quartz.NET, but it's too powerful for this easy task. Now I'm trying to use NCron, but it requires an initialiser in the Main() method (with obligatory parameter args):

class Program
{
    static void Main(string[] args)
    {
        Bootstrap.Init(args, ServiceSetup);
    }
}

Is there the way to do this in the Application_Start()? What should I pass as a args param? What other solutions can solve this task?


Solution

  • Author of NCron speaking…

    First: I have never myself integrated NCron into a web application, and I am not sure how well it will work. For instance, as Kenneth points out, IIS will shut down your app if it does not receive any traffic, and there might be other hiccups as well.

    In order to integrate NCron into a web app, I suggest that you ignore Bootstrap.Init() (designed specifically as an entry point to console apps) and rather work directly with SchedulingService:

    using (var service = new SchedulingService())
    {
        service.Hourly().Run<DataUpdateJob>();
        service.Daily().Run<RecycleCacheJob>();
    
        service.Start();
    }
    

    Again: I have never done this myself, but please do give it a try, and let me and everyone else know how you fare.