2

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?

3 Answers 3

3

Another option to consider is Postal. You can find a tutorial here to get started, or watch this video from MvcConf. You can send emails asynchronously using the Email.SendAsync() method.

Sign up to request clarification or add additional context in comments.

Comments

2

I wrote a project called ActionMailer.Net that allows you to generate emails from your MVC views. Give it a spin and let me know if you like it. I also wrote up some documentation and a nice screencast for the project. Cheers! :)

Comments

1

I would hyper strongly recommend you MvcMailer (note the Send Email Asynchronously section). You may also checkout Scott Hanslemann's blog post about it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.