ASP Express Home | What You Get | Pricing Information
New-->Online User Count
Using DatePart and other Date Functions
(Updated) Using Variables, Single & DoubleQuotes with SQL Statements in ASP
(Updated) Emailing Form Results
Mass Emailing with CDO
Using The Ad Rotator
ASCII Character Set 0-127
Mass Emailing With CDO
Naturally, first you've got to make a connection to the Database and get a little SQL going:
This is the code that actually grabs all the email addresses from the FieldName called 'email'. Once it has all the email addresses (putting a semi-colon in between each of them), it puts it in a variable called 'MyVar'.
MyConn.Open "PROVIDER=MSDASQL;" & _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"DBQ=" & server.mappath("MyDatabase.mdb")
MySQL="Select * from TableName"
delimiter = ""
do while not MyRs.eof
If Not IsNull(MyRs("email")) Then
MyVar= MyVar & delimiter & MyRs("email")
delimiter = "; "
Here, we set up the Body of the message - whatever you want, put it here and add vbcrlfs for formatting:
MyBody="This is everything I wanted to tell you." & vbcrlf & _
"Let Me know what you think & let me know." & vbcrlf & "Thank you for your support" & vbcrlf & "David Wier"
We're getting really close here - we instantiate the object that actually does the emailing. What I usually decide to do, is to put my own email address in as the main person to whom it's sent. That way, if I get it, I'm at least fairly certain that the mailing went through ok.
Set objEmail = Server.CreateObject("CDO.message")
objEmail.From = "Bobby@here.com"
objEmail.Subject = "This is the Subject of my Email!!"
Now - here's where we put in all the rest of the names. Remember that variable we created from the loop above? Well, this is where it goes - at least for me, that is. With all the email addresses in the BCC section, it looks like they're all sent individually (at least theoretically).
objEmail.TextBody = MyBody
Here's where you can simply do a response.write to insure yourself that 'MyVar' did indeed, make up all the email addresses you had thought it should:
Response.Write "Your Email was send to the following email addresses:" & MyVar
We must tidy up a little:That's all there is too it - that wasn't too hard, was it?
Set MyRs= Nothing
One note of warning, though - - - before you do this, you should delete all email addresses going to Hotmail.com. For some reason, which I have yet to figure out, some emails going to Hotmail.com get in the hotmail system and replicate - 100s or even 1000s to the same email address.