0

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.

tereško
  • 58,060
  • 25
  • 98
  • 150
Cincoutcin
  • 19
  • 3
  • Can you post the respective code? – rae1 Jan 28 '14 at 21:04
  • 1
    I believed Quartz.net is running on its own thread. And so your HttpContext is null because it is not running on the thread that MVC is running on. What exactly are you trying to get done? Why do you want HttpContext to format an email? – Chi Chan Jan 28 '14 at 21:13

1 Answers1

1

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.

EmailController.SendWelcomeEmail(int id)

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.

http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.defaultconnectionlimit(v=vs.110).aspx

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:

Send async e-mails

Community
  • 1
  • 1
Matt
  • 3,638
  • 2
  • 26
  • 33