MvcMailer and Quartz.Net httpContext is null
Okay, so I am trying to send out scheduled activity reminders via email every 30 minutes (If they scheduled an activity), and I have the Quartz stuff working and the MvcMailer worker, however, I am having trouble with getting the Quartz.Net to use the MvcMailMessages.
The error I am getting is: Value cannot be null. Parameter name: httpContext
How am I able to go about this? I have done a lot of searching but am not able to find anything that has worked. I have my Scheduler starting in the Application_Start() of the Global.asax.cs
I could just go back to using the default Email and then somehow format my message differently with all the Htmlz! But I'd rather not spend the time doing this.
Any help would be greaaatly appreciated.
I have done something similar. But I just used Quartz.NET to "pop" a controller URL that can then send the email.
Have a Job and a Trigger that you can schedule in Quartz.Net.
Create a Controller in your MVC site that can send your emails. Someting like EmailController
Have a ActionMethod for each email type you want to send out.
In your action method, query your database, do any logic, and ultimately invoke your MVCMailer to send out the email.
To invoke this from Quartz.Net you can just use WebClient()
var client = new WebClient(); client.DownloadString("yourwebsitehere/Email/SendWelcomeEmail/99999");
If you end up having scaling issues, remember to set the ServicePointManager.DefaultConnectionLimit to a high value.
Hope this helps guide you some. The key takeaway is that there are 2 process involved here. Your website and then a secondary process that will host Quartz.Net. Essentially you need to get the request to go back through the asp.net pipline so your HttpContext will be valid again.
Some additional stuff can be found in my answer here about properly Async sending the emails via MvcMailer: