Forum Moderators: open

Message Too Old, No Replies

ASP mail+cdonts

         

stevelibby

4:08 pm on Jan 10, 2006 (gmt 0)

10+ Year Member



hi
i have set up a mailing list on my site which works fine and have set a delay of 7 seconds between each mail.
How can i get the page to load first and then the script start rather than the way it is now that it send all th eemail before the page loads.

mrMister

11:38 am on Jan 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Set Response.Buffereing to true. Place your page rendering code at the top of the page. Then do a Response.Flush (this will output the contents of the page to the browser), then place your mail sending code after it.

stevelibby

12:31 pm on Jan 11, 2006 (gmt 0)

10+ Year Member



great! at least i know it can happen, however slow down a bit as this is an area i am not so sure on.
can you give me a more detailed description so that i can understand it.

mrMister

1:26 pm on Jan 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The best way would be to post your code as it is currently (or stickymail it to me if it's long) and I'll show you where the changes need to be made.

stevelibby

12:22 pm on Jan 12, 2006 (gmt 0)

10+ Year Member



Hi this is the code:
<%

'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!

mrMister

8:34 am on Jan 13, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<%

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]

mrMister

8:43 am on Jan 13, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just for the record. This isn't the best way of doing things.

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.

mrMister

9:23 am on Jan 13, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I just remembered that there's a component from ServerObjects that will do the pause without maxing out your CPU. You can find it here...

[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.

stevelibby

11:44 am on Jan 13, 2006 (gmt 0)

10+ Year Member



the pause is because the server request a time delay of 7 seconds, there terms and conditions.

mrMister

12:02 pm on Jan 13, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In that case, you'll most likely be breaking the Ts & Cs if two people send an email within 7 seconds of each other.

stevelibby

12:25 pm on Jan 13, 2006 (gmt 0)

10+ Year Member



yeah i know but there is only me, so i think for the time being i`ll be ok.

stevelibby

12:43 pm on Jan 13, 2006 (gmt 0)

10+ Year Member



with reference to the script, yes it works, however i was expecting that it list each email as it was sent! howvere this is not the case, it lists them at the end!