There are a few similar questions. I just want to clarify one part.
If I want to send an e-mail (up to 30) in response to user's action, what execution context do I do it from?
Do I do a sync call (mail server is in the same data center, so actual sending is fast)?
Do I spawn a thread and send it from there? such that each user-request-to-send mail gets handled by a new thread?
The biggest issue I think, is that it is a shared web hosting. So I don't know what's a good way to install/start a windows service, or start a dedicated thread.
Details: ASP.NET MVC app, hosted on IIS 7.0 integrated mode, on discountasp.net using discauntasp.net smtp server.
Is there a better way? What's a "standard" way to accomplish this?
Most datacenters have an smtp address that they can provide you in order to send mail. I'd just create the mail object and send it to that local smtp server. If you don't have access to one then you can have your smtp adapter connect to an external service and provide it's authentication information which should let you send mail through it. Non local addresses usually require this.
If you have to send a substantial amount of mail out or your server has a high load I suggest that you do either spawn a different thread or if you have access to the box that you add in a service that can pick up the items and send them out apart from your web application. This is because threads in your web app could be recycled or die and if you do end up with a long running process this could mean data loss or loss of functionality. By establishing a queue you can provide fast functionality to your users without compromising the QoS.
If as you suggest that this is a shared box then you will want to spawn a new thread to do this action for you. Reactive extensions can provide a more robust way for you to do this and is a part of the TPL (Task Parallel Library). Let me know if you need any more specific examples.