Forum Moderators: open
'Loop until we've hit the EOF (end of file)
Do Until objRS.EOF = True
Dim strHTML
strHTML = "<html><head><title>Test Email</title></head>"
strHTML = strHTML & "<body bgcolor=#FFFFFF>"
strHTML = strHTML & "Hi " & objRS("Fname") & " " & objRS("Lname") & "<BR><BR>"
strHTML = strHTML & objRS("Body")
strHTML = strHTML & "</body></html>"
'Set up the email object
Dim objMail
Set objMail = Server.CreateObject("CDONTS.NewMail")
With objMail
.From = "email.co.uk"
.To = objRS("Email")
.Subject = objRS("Subject")
.BodyFormat = 0 'CdoBodyFormatHTML
.MailFormat = 0 'CdoMailFormatMime
.Body = strHTML
.Send
Response.Write "<BR>Your e-mail to " & objRS("Email") & " has been sent. <BR>"
End With
Set objMail = Nothing
'Move to the next record (important!)
objRS.MoveNext
EndTime = Now() + (7 / (24 * 60* 60)) '7 seconds
Do While Now() < EndTime
'Do nothing
Loop
Loop
'Close the Recordset object
objRS.Close
'Delete the Recordset Object
Set objRS = Nothing
'Close the Connection object
objConn.Close
'Delete the Connection Object
Set objConn = Nothing
%>
Im not so sure i need that second loop!
Response.buffer = True
'Loop until we've hit the EOF (end of file)
Do Until objRS.EOF = True
Dim strHTML
strHTML = "<html><head><title>Test Email</title></head>"
strHTML = strHTML & "<body bgcolor=#FFFFFF>"
strHTML = strHTML & "Hi " & objRS("Fname") & " " & objRS("Lname") & "<BR><BR>"
strHTML = strHTML & objRS("Body")
strHTML = strHTML & "</body></html>"
'Set up the email object
Dim objMail
Set objMail = Server.CreateObject("CDONTS.NewMail")
With objMail
.From = "email.co.uk"
.To = objRS("Email")
.Subject = objRS("Subject")
.BodyFormat = 0 'CdoBodyFormatHTML
.MailFormat = 0 'CdoMailFormatMime
.Body = strHTML
.Send
Response.Write "<BR>Your e-mail to " & objRS("Email") & " has been sent. <BR>"
Response.flush
End With
Set objMail = Nothing
'Move to the next record (important!)
objRS.MoveNext
EndTime = Now() + (7 / (24 * 60* 60)) '7 seconds
Do While Now() < EndTime
'Do nothing
Loop
Loop
'Close the Recordset object
objRS.Close
'Delete the Recordset Object
Set objRS = Nothing
'Close the Connection object
objConn.Close
'Delete the Connection Object
Set objConn = Nothing
%>
Im not so sure i need that second loop!
If your intention is to leave a 7 second delay after each email sent and there's a chance that the code might send more than one email then leave it in.
[edited by: mrMister at 8:43 am (utc) on Jan. 13, 2006]
I have a feeling that your code will chomp up all of your processor cycles for 7 seconds whilst it waits, slowing down your site if you have more than one concurrent user.
Also, your code doesn't prevent over users sending mail at the same time. For example if you have two users each sending mails, there is a chance that each mail could be sent at roughly the same time (so your 7 second delay doesn't take effect)
Ideally, you want to be creating a service on the machine which deals with your mail queuing and sending. The ASP code should just send the details of the mail to the service and then end its processing, leaving the service to do the job of queueing all the mails from all the users and calculating the 7 second pause in the background.
However, that would trake quite a bit more programming to do, so if your server isn't under too much load and you are happy to accept the above caveats, you can probably get away with it.
[serverobjects.com...] (WaitFor 1.0)
You might also be interested in their AspQmail object as well, depending on exactly why you're pausing your mail sending.