I have a main application in asp.net.
There I have an option to send mail via SMTP. I want to make a separate mail sending process. That means if I click on SEND MAIL button, the mail should be sent from background without affecting the application (Like separate service). I have tried using separate thread and its working fine but is there any possibility to make separate mail sending process without affecting the main application. If I close the application (app pool), then also it should send the mail.
Thanks.
Implement the mail sending logic as a Windows Service and use IPC (for example shared memory via Mutex and MemoryMappedFile) to communicate between your ASP.NET app and the Windows Service.
This has the benefit that the mail sending logic runs as long as the machine is up… if you need persistence (for example to remember unsent messages after a reboot) you can use a DB or the filesystem…
EDIT – much easier option:
Setup an SMTP Pickup folder in IIS (it has this option built-in!) and configure your ASP.NET app accordingly (see for example http://www.singular.co.nz/blog/archive/2007/11/28/using-an-smtp-pickup-directory-delivery-method-for-asp-net-development.aspx and http://www.singular.co.nz/blog/archive/2007/12/19/programmatically-setting-the-smtpclient-pickup-directory-location-at-runtime.aspx).
This way your app saves the Mails as .eml files into the directory and IIS takes care of the rest (sending/resending/logging etc.).
SmtpClienthas the ability to work with pickup folder already built-in!