Threads/WebServices in Webserver
I'd like to know wich is the best way to create a background task in the server, to send e-mails.
The idea is that a person bids an item, and this automaticly sends a mail to the task responsible wich it sends the mail to the correspondent person, but how can i do this without affecting the website functionality or making it slow.
I've read some things about async tasks but not sure if this is the solution to my problem.
You can create asynchronous background threads, look at the usage of the .NET framework Task class if you are using .NET 4.x, in prior versions you have to look at Thread or ThreadStart. But be careful with accessing data, to prevent the main thread and your email thread from getting into problems, you also need to look at locking resources with the "lock" statement.
This is good, if you need to send many emails in one go and this should be done asynchronously, which means "the user should not have to wait for it". In the web, this is also the best way to do such things in a thread, as you could get a request time out if it takes too long. But of course, at the end of the thread, you should somehow create a report and also send that to the executing user, so that he knows that mailing has finished or if any errors occured.
We solved this in our company by creating a web service which is responsible for shipping emails to the SMTP service and log them, including content and status of email sending. Our apllications build up the emails in the format defined from our web service and they are responsible for staus report for the end user.
Of course by doing this, you will still need to have a layer which builds up the email you want to send and the forward it to the mail service, and this maybe still needs to be done async. so only the relaying to SMTP itself would be separated from your application like this.
But if you have an application which needs to do mass mailing or something like that and you want to separate it from your "normal" tool, (e.g. for separating processes and process load) then simply create a separate service which "knows" the domain of your main application.
By doing this, you would only have to trigger the mailing service by sending the according information from the main application to the mailing service. But again, maybe you need to build up a background thread which collects and sends the information required to that service.
You could create this service in many ways, using WCF for example, as background windows service with message enqueing, or a HTTP based service with a rest API, etc. etc.
You did not give that much information about what you need to do, but maybe this will point you to the right direction.