views:

644

answers:

7

I need to send emails via a background job on a classic-asp app so the user doesn't have to wait for a slow webserver to complete sending the email.

I know I can use Ajax to generate two separate requests, but I'd rather not require Javascript. Plus, I suspect there's a better way to pull this off. Ideas?

+1  A: 

Hi Cory,

Sorry, but as far I as know there were no ways of generating a separate thread using old ASP.

If you don't want AJAX what about a hidden IFRAME? ugly but it works...

tekBlues
+8  A: 

You are thinking too narrowly. You don't have to send the email from ASP. Put it into a database and then have a separate program that runs, say, every minute and send all the emails that are in the database.

tomjen
+1. The simplest solution is a VBScript running as a scheduled task.
AnthonyWJones
Great answer, I'd considered this, but would like to avoid the 1 minute delay required in using a scheduled job and overhead of connecting/reading/writing to the db every minute. So there is no way to trigger a separate program to run in the background from VBscript?
Cory House
+2  A: 

There are 3rd party COM objects you can get that handle mail much better than what is built into IIS. You just pass your message off and it handles the queue so your program gains control back immediately.

Diodeus
A: 

A good way to speed this up would be to instruct CDOSYS to use the IIS pickup directory of your web server (typically c:\inetpub\mailroot\pickup). Assuming your web server has the SMTP Virtual Server installed.

Another similar and yet faster option would be to manually generate *.EML files and put them in the pickup directory. Also to avoid possible conflicts you could put the files in a temporary directory and then have a batch file move them to the pickup directory at certain intervals.

thomask
+3  A: 

I would agree with tomjen on this one. Saving the email in a database table and then using a back-end process to actually send the email works really well, especially if you are sending large volumes of email. I would recommend Perl for doing the back-end mailer as there are several packages that will easily get the job done.

Rhinosaurus
+1  A: 

If you don't want to use my other suggestion, you might want to consider running a different program that just sends email and then communicate with this program through COM or a (local) tcp socket. This should be much faster than having to connect to a server over the internet, and you avoid the delay of using a database.

tomjen
+2  A: 

Persits produces the well-known AspEmail COM component that comes with a mail queuing system that will do what you need.

http://www.aspemail.com/manual_07.html

Your code essentially hands off the sending of the message to a queue daemon that runs on the server and sends whatever mails are in the queue in a separate process, thereby not holding up your ASP script from finishing its execution.

Frank Bailey
Thanks Frank - After posting this I realized we actually had a license for persists and their queuing setup is working great!
Cory House
Glad to be able to help. :)
Frank Bailey