There is no reliable way to run something at a certain time in ASP.NET MVC. There is not even a reliable way to run something in the background thread.
The cause of insecurity is the completely external control of the lifetime of the application. Those. if IIS wants to kill or put to sleep your application due to user inactivity, memory overruns, just on schedule, for any other reason - it will kill. And no code that will have to work in the hour X - will not work.
In addition, with certain settings, IIS can run two or more simultaneous processes for the same application, and your code to run on a schedule will run twice.
Reliable ways:
- To carry out processing almost in windows service where it is possible to organize the reliable timer.
- Deliver mail processing in the console application, put it to execution in the Task Scheduler.
- Leave mail processing in ASP.NET / MVC, but link it to a specific url. Make a simple Windows Service / Console + Task Scheduler / use ready-made jobs from your hoster to call this url.