I want to send a bunch of emails, and the obvious way to format them is to render a partial view and send that. The problem is that I'd like to do this in the background, so it isn't immediately obvious how to get access to the methods I need.
Since the job is kicked off by a controller, one thing I was thinking of was something like this:
public ActionResult SendEmails(){
Task.Factory.StartNew(() => DoSendEmails(
// pass in a formatting closure that has access to the
// controller's context
delegate(EmailData) {
return RenderPartialToString("view", EmailData);
}
));
}
Will this work? Is there a better way?