I'm writing a user registration process in ASP.NET MVC 3 RC, and I'd like to send a confirmation email to the user during that process. I know I can do this using the classes in the System.Net.Mail
namespace, but I have a few questions on the best way to implement this.
Before I go down the path of writing my own code to send email, are there any existing solutions like ActionMailer for ASP.NET MVC?
If I do roll my own, should I do this on the web server during the request and would using Send bog down the web server, tying up threads as they wait开发者_开发问答 on the SMTP server to respond? If so, would SendAsync be preferable?
Would it be better pull this out of ASP.NET MVC entirely, maybe by writing a record to a database table and having a windows service periodically sweep the table and send out the messages?
At the moment, I am leaning towards #3, since that would give me the flexibility of doing this work on another server entirely, but was wondering what others are doing. Are there options and/or issues I haven't considered?
Personally I would agree that #3 is your best option. It's the most complex of the three, but none of them are terribly complex. What it does do, however, is:
- Give you a record of all emails sent by the system.
- Remove the dependency of the email system from the live application. (Separation of concerns is always fun.)
- Provide a natural re-try mechanism when the email system dependency is failing.
As for an existing library for making the creation/sending of the MailMessage
objects easier, I've never seen a need. If you're just sending the messages to an SMTP server, the built-in objects are more than adequate and easy to use.
MvcMailer is like an ActionMailer for .Net. See the NuGet package here and the project documentation
Hope it helps!
精彩评论