By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,805 Members | 1,202 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,805 IT Pros & Developers. It's quick & easy.

Emailing to schools on our database

P: 7
Am trying to write some vbscript coding to send emails to records on our schools database. This is how far I've got. Am not an expert!! :


Dim myConn, myCmd, myRS, firstRecord
dim strSQL2, fldCurrentID, myCmd2 'NEW

Set myConn = Server.CreateObject("ADODB.Connection")
Set myCmd = Server.CreateObject("ADODB.Command")
Set myRS = Server.CreateObject("ADODB.Recordset")

Set Mailer = Server.CreateObject ("SMTPsvg.Mailer")
Mailer.FromName = "Joe's Widgets Corp."
Mailer.FromAddress = ""
Mailer.Subject = "Your Widget Order"
Mailer.BodyText = "Your order was processed."
Mailer.RemoteHost = ""

myConn.Open("dsn= ;uid= ;password= ")

strSQL = "SELECT tblselectedschools.fldContact, tblselectedschools.fldemail FROM tblschools RIGHT JOIN tblselectedschools ON tblschools.fldSCHOOL_ID = tblselectedschools.fldSCHOOL_ID WHERE tblselectedschools.fldUserID = " & UserID & " AND tblselectedschools.fldSelected = 1"

With myCmd
.ActiveConnection = myConn

.CommandText = strSQL ' This should be your SQL select statement
.CommandType = 1 'adCmdText
End With

With myCmd2
.ActiveConnection = myConn

.CommandText = strSQL ' This is the SQL statement for UPDATE query to change the fldmessagesent field
.CommandType = 1 'adCmdText
End With

strSQL2 = "UPDATE tblselectedschools SET fldmessagesent=0 WHERE fldID = " & fldCurrentID

myRS.Open myCmd


Do While Not myRS.EOF

if Mailer.SendMail then
' Message sent sucessfully

If firstRecord = 1 Then
firstRecord = 0
Mailer.AddRecipient myRS.Fields("fldContact"), myRS.Fields("fldemail")
Mailer.AddBCC myRS.Fields("fldContact"), myRS.Fields("fldemail")

End If

' Message send failure
'WRITE 0 TO fldmessagesent in tblselectedschools

fldCurrentID = myRS.Fields("fldID")
myRS.Open myCmd2
myRS.Close myCmd2

end if




The idea is to set fldmessagesent=1 by default and only set it to false(0) if the message is not sent, but having the two myRS.OpenMyCmd... statements nested - will this work, or is there a better way of doing it.

Also, as there may be 1000 emails or more, should they be sent in "blocks" of say 50 at a time. If so, how can I do that?

Anyone's help would be much appreciated

Sep 18 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.