Forum Moderators: open

Message Too Old, No Replies

Cdonts

         

stevelibby

5:56 pm on Jun 23, 2005 (gmt 0)

10+ Year Member



Hi
i have been searching all day, i have managed to create a page which will send emails to my customers via db.
my problem is that i want to put a delay in between each email being sent by 7 seconds, i know that in pearl it sleep, what can i do with cdonts? also some script show "wend" whats that all about?

qlipoth

9:15 pm on Jun 23, 2005 (gmt 0)

10+ Year Member



A way to wait 7 seconds (Not the best, just the simplest way that works in pretty much every language):

1) set a variable to the current time + 7 seconds
2) set up a while loop to run and do nothing until the current time is greater than the variable value.

There are probably much better ways to do this, but I don't know what language you're using.

stevelibby

9:20 pm on Jun 23, 2005 (gmt 0)

10+ Year Member



Hello there,
this is the code that i currently have:

Dim strSQL
strSQL = "SELECT *, CustomerID AS Expr1, Name AS Expr2, Email AS Expr3, Test AS Expr4 FROM mailtest;"

objRS.Open strSQL, objConn

'Loop until we've hit the EOF (end of file)
Do Until objRS.EOF = True


'Set up the email object
Dim objMail
Set objMail = Server.CreateObject("CDONTS.NewMail")
With objMail
.From = "Admin Email"
.To = objRS("Email")
.Subject = ("subject")
.BodyFormat = 0 'CdoBodyFormatHTML
.MailFormat = 0 'CdoMailFormatMime
.Body = strHTML
.Send
Response.Write "Name = " & objRS("Name")
Response.Write "<BR>Email = " & objRS("Email")
Response.Write "<BR>Your e-mail has been sent. <BR><BR>"
Response.Write "<P><HR><P>"

End With
Set objMail = Nothing

'Move to the next record (important!)
objRS.MoveNext
Loop

what do i need to do?

qlipoth

9:42 pm on Jun 23, 2005 (gmt 0)

10+ Year Member



something like:

---

Dim strSQL
strSQL = "SELECT *, CustomerID AS Expr1, Name AS Expr2, Email AS Expr3, Test AS Expr4 FROM mailtest;"

objRS.Open strSQL, objConn

'Loop until we've hit the EOF (end of file)
Do Until objRS.EOF = True

'Set up the email object
Dim objMail
Set objMail = Server.CreateObject("CDONTS.NewMail")
With objMail
.From = "Admin Email"
.To = objRS("Email")
.Subject = ("subject")
.BodyFormat = 0 'CdoBodyFormatHTML
.MailFormat = 0 'CdoMailFormatMime
.Body = strHTML
.Send
Response.Write "Name = " & objRS("Name")
Response.Write "<BR>Email = " & objRS("Email")
Response.Write "<BR>Your e-mail has been sent. <BR><BR>"
Response.Write "<P><HR><P>"

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

-----

This will, in all likelyhood, cause your page to time out on running it, as ASP has to render ALL of it's scripting before the page displays.

If it's vital that this run from the web : [support.microsoft.com...]
will show you how to change timeouts.

Probably not the best solution, still, but it's the only way I can think of to do this in ASP

stevelibby

10:33 pm on Jun 23, 2005 (gmt 0)

10+ Year Member



i have just tried it an it in order to sent 4 emails. Thank oyu
However should this part be the other way round?

'Move to the next record (important!)
objRS.MoveNext

EndTime = Now() + (7 / (24 * 60* 60)) '7 seconds
Do While Now() < EndTime
'Do nothing
Loop

Loop

the time piece being before the obj.rs.MoveNext?

Krapulator

2:16 am on Jun 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A script like this is bound to max out your servers CPU while it is looping. I think there's a server compenent you can install which let you call a delay without maxing the server out.

coffeebean

4:44 am on Jun 24, 2005 (gmt 0)

10+ Year Member



You could try AspQmail instead of cdonts [serverobjects.com...]

Lets you queue emails to be sent by a service outside of IIS, so the ASP scripts don't have to hang - just add to the queue and tell it what time to send.

Mailer.QMessage = true
Mailer.QTime = "07/30/00 22:10:00"

GaryK

4:48 am on Jun 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The same site offers a free download called WaitFor. It's a COM object that lets you pause a preset amount of time.

qlipoth

2:54 pm on Jun 24, 2005 (gmt 0)

10+ Year Member



From Steve: However should this part be the other way round?

It shouldn't matter where you put the wait, really. Either way you'll pause 7 seconds between iterations

The queue mail is a much better option.

stevelibby

3:04 pm on Jun 24, 2005 (gmt 0)

10+ Year Member



hi
i have just done a mail send to a base of about 800 people, but it didnt and hasnt stopped? why? this is the code?

objRS.Open strSQL, objConn

'Loop until we've hit the EOF (end of file)
Do Until objRS.EOF = True

Bla,bla

Response.Write "Name = " & objRS("Name")
Response.Write "<BR>Email = " & objRS("Email")
Response.Write "<BR>Your e-mail has been sent. <BR><BR>"
Response.Write "<P><HR><P>"

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

kona

4:12 pm on Jun 24, 2005 (gmt 0)

10+ Year Member



System.Threading.Thread.Sleep( <time in milliseconds> )

stevelibby

4:20 pm on Jun 24, 2005 (gmt 0)

10+ Year Member



Sorry im not wiht you on that one?

kona

5:01 pm on Jun 24, 2005 (gmt 0)

10+ Year Member



It's the proper way to wait for a given time period.

If you do something like this (as you posted above):
EndTime = Now() + (7 / (24 * 60* 60)) '7 seconds
Do While Now() < EndTime
'Do nothing

you'll be maxing out your CPU (and slowing down any other programs that are running) while waiting for the 7 seconds to pass.

stevelibby

6:25 pm on Jun 24, 2005 (gmt 0)

10+ Year Member



real stupid question, but can anyone give me any clues as to why the script ran through the database 3 times?

qlipoth

8:09 pm on Jun 24, 2005 (gmt 0)

10+ Year Member



Kona: If I'm not mistaken System.Threading is .Net and not available in old ASP. PLEASE correct me if I'm wrong here.

Stevelibby:
Again, the queued mail system is a much better solution than the one I presented.

I don't think that it would run 3 times based on the code we've got here... might want to check your database and make sure that the entries aren't duplicated. Or to be completely sure, put the keyword "DISTINCT" in front of Email in your SQL

kona

9:44 pm on Jun 24, 2005 (gmt 0)

10+ Year Member



qlipoth: you're absolutely right, I skimmed through the first post and thought it was vb.net.

stevelibby

10:49 pm on Jun 24, 2005 (gmt 0)

10+ Year Member



no sorry , i should have explained it normal asp. what needs changing?

qlipoth

9:26 pm on Jun 27, 2005 (gmt 0)

10+ Year Member



Nothing needs changing... but in order to make use of thread.sleep and/or other more intelligent means of waiting, you'll need to use a com object. What I'm given you is quick and dirty and good for small numbers of records only.