4

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?

5
  • 4
    Better way: don't use classic ASP. Sorry, I couldn't resist. :)
    – Zifre
    Jun 4, 2009 at 20:28
  • 1
    He's not being a hater - he's being a realist. Jun 5, 2009 at 1:45
  • 1
    @John, Zifre: This is a case of the question implying a partial solution to the problem rather than simply stating the problem. The question should be "How can I get my classic ASP app to send emails in the 'background'?". You are right, realistically ASP doesn't do multi-threading but that really isn't the problem here. Jun 5, 2009 at 7:44
  • @Zifre - Couldn't agree more. After doing .net for long going back to classic feels like punishment.
    – Cory House
    Jun 5, 2009 at 12:34
  • 1
    @John - It's not being a realist when you're developing for a client that needs a simple fix on what's broken and isn't interested in an upsell. If only the answer was always as simple as forcing an upgrade to the latest stack
    – Cory House
    Jun 5, 2009 at 12:42

7 Answers 7

11

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.

2
  • 2
    +1. The simplest solution is a VBScript running as a scheduled task. Jun 5, 2009 at 7:39
  • 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
    Jun 5, 2009 at 13:39
3

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.

2

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.

2

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.

1
  • Thanks Frank - After posting this I realized we actually had a license for persists and their queuing setup is working great!
    – Cory House
    Jun 26, 2009 at 12:50
1

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...

1

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.

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.