Beyond a Listserve
If this was all we did, it would still be better than a simple listserve, but we can take it even a step further. Because we are feeding from the database, we can personalize each message. Of course, then we'll have to send off individual messages for each user rather than simply adding all users to a single message. We'll do this with a slightly modified version of the form action, Listing 5.
We haven't really restructured too much to add this functionality; we've moved around only the actual sending of the mail. Because we haven't collected a great deal of information about our users, we'll assume that we want to insert either their first name, their last name, or both into the subject line or the message. To do this, we'll have the person sending the messages include "tokens" in the message. To insert the user's first or last name, all we need is "*FIRSTNAME*" or "*LASTNAME*" within the body of the subject or message. To insert them into the text, we simply use the VBScript replace() function.
Other than that, the only significant change is that we are using this line to clear the address field between messages:
In addition, we are sending off each message as we generate it, rather than waiting until we have run through the entire group.
Note that if you are sending messages to a significant number of users, it takes a significantly longer amount of time for the messages to be sent. With enough messages, your application may even time out. In order to avoid this, ASPEmail has a second command, Mail.SendToQueue, that allows the application to hand off the messages to Email Agent, which sends them after the script has completed.