Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 373
  • Last Modified:

How can I have page render first, then execute classic asp? (want to speed up page response)

Hi,
I have an ASP page that processing a form's submit button. The ASP generates a bunch of emails based on controls selected on the form by the site visitor and also displays a confirmation page, e.g. "Thank you for your registration".

The problem is that the the Confirmation page is not served up to the visitor until all the ASP processing is complete and since this now includes sending emails, it is very slow (up to 60 seconds).

Does anyone know how I could force the confirmation message to show on the page *before* all the ASP processing occurs?

Thanks,
Gwenda
0
gwendaellwood
Asked:
gwendaellwood
  • 5
  • 5
  • 4
  • +1
3 Solutions
 
Wayne BarronCommented:
what email processing are you using?
Should not take no 60 seconds to process a page and send an email
Unless you are sending out a LOT of emails.

So.
It you are using a CDOSYS or equal mailing system.
Then the process is automatic on the visitor's end.
The only thing that would slow it down would be the way that you have it written up.

Carrzkiss
0
 
kevp75Commented:
add a response.flush in before the email send code.
0
 
Abiel de GrootCommented:

You could also use the Queue method. If you do not all the emails are sent one by one and the web server has to negotiate with the smtp server for each send. The web server has to wait for a response from the mail server for each message. The Queue method simply put the messages in the mail servers Queue folder and thats it. By default the mail server will send messages from its queue folder in stacks of 50 so its much more efficient all round.

I use Persits asp mail, however, the queue folder method would exist for other mail sending components too.

Kind regards

A.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Abiel de GrootCommented:
On my code it looks like this

Set Mail = Server.CreateObject("Persits.MailSender")
Mail.Charset = "UTF-8"
Mail.ContentTransferEncoding = "quoted-printable"
Mail.Username = E_Email_UN
Mail.Password = E_Email_PW
Mail.Queue = True  '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< QUEUE
Mail.Host = E_SMTP_Server
0
 
Wayne BarronCommented:
gwendaellwood,
What about it. Are you still experiancing this issue?
If so, please come back in and let us continue to help you.

Carrzkiss
0
 
gwendaellwoodAuthor Commented:
hi carrzkiss , kevp75 and Jonbysoft and  thanks for the help. I'm going to move the code out of the <Head> section where it seems to get processed before the page is rendered. Then I'll put a response.flush at the top of the code to see if that makes the page appear before the code gets processed. Also I'll find out from the ISP if the mail object I'm using has a Queue (as in Mail.Queue=True like Jonbysoft's code), and if it does I'll try that first.

I've attached the slow running code as it is now
mail-code.txt
0
 
Wayne BarronCommented:
To begin with.
You was creating to many IF Statements.
Doing
If
End if
Every one is a wayste of resources.
If
ElseIF
End IF
Will look at each one and resume next.

Example of your code changed to use the
ELSEIF

(Code untested)
The ELSEIF will not use up a lot of un-needed resources.

Good Luck
Carrzkiss
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
 
<head>
<%@ LANGUAGE = "VBSCRIPT" %>
<%
 
dim strThankYouMsg
dim strLocalContactName
dim strLocalContactEmail
dim strLocalContactSubject 
dim strSelections
dim xmlhttp
 
 
'do a bunch of processing here to develop a string of selections from the form
 
'
' city list
if request.form("barrie")= "ON" then 
	strLocalContactName = "name"
	strLocalContactEmail= "whatever@whatever.ca"
	strLocalContactSubject = "Please send me Barrie local notices"
	call EmailLocalMailingList(strLocalContactName , strLocalContactEmail, strLocalContactSubject)
elseif request.form("calgary")= "ON" then 
	strLocalContactName = "name"
	strLocalContactEmail= "whatever@whatever.ca"
	strLocalContactSubject = "Please send me Calgary local notices"
	call EmailLocalMailingList(strLocalContactName , strLocalContactEmail, strLocalContactSubject)
elseif request.form("halifax")= "ON" then 
	strLocalContactName = "name"
	strLocalContactEmail= "whatever@whatever.ca"
	strLocalContactSubject = "Please send me Halifx local notices"
	call EmailLocalMailingList(strLocalContactName , strLocalContactEmail, strLocalContactSubject)
elseif request.form("montreal")= "ON" then 
	strLocalContactName = "name"
	strLocalContactEmail= "whatever@whatever.ca"
	strLocalContactSubject = "Please send me Montreal local notices"
	call EmailLocalMailingList(strLocalContactName , strLocalContactEmail, strLocalContactSubject)
elseif request.form("ottawa")= "ON" then 
	strLocalContactName = "name"
	strLocalContactEmail= "whatever@whatever.ca"
	strLocalContactSubject = "Please send me Ottawa area local notices"
	call EmailLocalMailingList(strLocalContactName , strLocalContactEmail, strLocalContactSubject)
 
elseif request.form("toronto")= "ON" then 
	strLocalContactName = "name"
	strLocalContactEmail= "whatever@whatever.ca"
	strLocalContactSubject = "Please send me Toronto area local notices"
	call EmailLocalMailingList(strLocalContactName , strLocalContactEmail, strLocalContactSubject)
 
elseif request.form("vancouver")= "ON" then 
	strLocalContactName = "name"
	strLocalContactEmail= "whatever@whatever.ca"
	strLocalContactSubject = "Please send me Vancouver local notices"
	call EmailLocalMailingList(strLocalContactName , strLocalContactEmail, strLocalContactSubject)
elseif request.form("winnipeg")= "ON" then 
	strLocalContactName = "name"
	strLocalContactEmail= "whatever@whatever.ca"
	strLocalContactSubject = "Please send me Winnipeg local notices"
	call EmailLocalMailingList(strLocalContactName , strLocalContactEmail, strLocalContactSubject)
 
elseif request.form("ReferrerPage")="French" then
	stringPost = stringPost + "&group[1285177]=1"
	strThankYouMsg = "Votre information a été soumise. Vous recevrez une confirmation par courriel, " & _ 
	 "si vous avez donné votre adresse courriel. Vous recevrez dorénavant les avis. À noter que les avis locaux pourraient prendre jusqu'à 4 semaines avant de débuter."
	strThanks = "Merci"
else
	strThankYouMsg = "Your information has been submitted. You " & _
        "will receive a confirmation email shortly. " & _
        "You will begin receiving notices now. NOTE: Local notices may take up to 4 weeks to begin."
    strThanks = "Thank you"
end if
 
 
<%
Sub EmailLocalMailingList(strAddressee, strEmail, strSubject)
'SEND EMAIL CONFIRMATION TO LOCAL MAILING LIST CONTACT
	Set objMail = Server.CreateObject("SMTPsvg.Mailer")
		objMail.FromName = "Words Of Peace"
		objMail.FromAddress = "info@wordsofpeace.ca"
		objMail.RemoteHost = "mail.wordsofpeace.ca" ' Specify a valid SMTP server
		objMail.AddRecipient strAddressee , strEmail
		objMail.Subject = strSubject 
 
	txtBodyText =  _
		"Lastname: " & request.form("emma_member_name_last")  & VbCrLf & _
		"Firstname: " & request.form("emma_member_name_first")  & VbCrLf & _
		"Address: "  & rtrim(request.form("emma_member_street_address"))  & VbCrLf & _
		"City: "  & request.form("emma_member_city") & VbCrLf & _
		"Prov: "   & request.form("emma_member_province")  & VbCrLf & _
		"Postal Code: "  & request.form("emma_member_postal_code")  & VbCrLf & _
		"Email: " & request.form("emma_member_email") & VbCrLf & _
		"Phone: " & request.form("PhoneAreaCode") & " " & request.form("phone") & VbCrLf & VbCrLf & _
		strSelections
	
				
		objMail.BodyText = txtBodyText	
		objMail.SendMail 
		Set objMail = Nothing
end sub
%>
</head>

Open in new window

0
 
gwendaellwoodAuthor Commented:
Carrzkiss - thank you for looking at my code.
The webiste visitor might choose more than option, tho, and your Elseif structure will go to Endif as soon as it encounters a True, meaning that it will stop processing as soon as it finds the first checkbox = "ON".
I haven't the other solutions yet but will try them tonight.
Gwenda
0
 
Wayne BarronCommented:
humm. OK.

Let me know?

Carrzkiss
0
 
Abiel de GrootCommented:
Hi gwendaellwood,

Firstly, yes... MOVE ALL THIS OUT OF THE HEAD!. The HEAD is the first part of the web page. You need all this happening before the web page is rendered. I'm thinking, the reason you put the code within the head was to catch foreign characters. However, if you start you VB code with the line

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>

CODEPAGE="65001 will load the UTF character set which covers everything.


Secondly, the main reason you are getting a delay is this line.

call EmailLocalMailingList(strLocalContactName , strLocalContactEmail, strLocalContactSubject)

I am guessing the function EmailLocalMailingList() is actually sending the message. If you do not use a Queue method your web server will wait for a response from the mail server before proceeding to the next line of your code.

You are opening and closing the mail object each time rather than collecting a comma deliminated string Opening the mail object send all the emails and closing the mail object. In addition use the Queue method.

I often send email bulletins from my web applications, and sending 1 or a 500 takes nearly the same time!

0
 
Abiel de GrootCommented:
I would do it like this.

Kind regards

Abiel M de Groot Sanders

--------------------------------------------------------------------------------------------------------------------------------------------------------------
Start by changing the checkboxes so as they are all called the same think (EG chk_Cities) the value of each will be the city name. Then collect them as such:

SelectedCheckboxes = request.form("chk_Cities")

The FORM object only return checkboxes which have been checked, so you can expect back something like this

calgary, montreal,ottawa

They will automatically be comma deliminated.

Then send this string to the email script where you will convert it into a one dimensional array

call EmailLocalMailingList(SelectedCheckboxes)

Make another SUB where you place you variables into a select Case like this


--------------------------------------------------------
Sub ReturnMyVariables(PassedCity)
Select Case PassedCity
Case barrie
      strLocalContactName = "name"
      strLocalContactEmail= "whatever@whatever.ca"
      strLocalContactSubject = "Please send me Barrie local notices"

Case calgary
      strLocalContactName = "name"
      strLocalContactEmail= "whatever@whatever.ca"
      strLocalContactSubject = "Please send me Calgary local notices"

Case halifax
      strLocalContactName = "name"
      strLocalContactEmail= "whatever@whatever.ca"
      strLocalContactSubject = "Please send me Halifx local notices"

Case montreal
      strLocalContactName = "name"
      strLocalContactEmail= "whatever@whatever.ca"
      strLocalContactSubject = "Please send me Montreal local notices"

End Select
End Sub
I only put a few, you need all of them as above.
--------------------------------------------------------


We can now open the mail object loop over all the array from the check box send all the messages and close the mail object.

Sub EmailLocalMailingList(PassedString)

Dim Array cities, i

Arraycities = Split(PassedString,,)
If IsArray(Arraycities) Then

Call ReturnMyVariables(Arraycities(i)) set the correct variables for this email

Open Mail Object() Whichever you are using

For i = 0 To Ubound(Arraycities)
---------------------------------------------------

Put your mail sending script in here

---------------------------------------------------
NEXT

Close Mail Object()
End If


if request.form("ReferrerPage")="French" then
      stringPost = stringPost + "&group[1285177]=1"
      strThankYouMsg = "Votre information a été soumise. Vous recevrez une confirmation par courriel, " & _
       "si vous avez donné votre adresse courriel. Vous recevrez dorénavant les avis. À noter que les avis locaux pourraient prendre jusqu'à 4 semaines avant de débuter."
      strThanks = "Merci"
else
      strThankYouMsg = "Your information has been submitted. You " & _
        "will receive a confirmation email shortly. " & _
        "You will begin receiving notices now. NOTE: Local notices may take up to 4 weeks to begin."
    strThanks = "Thank you"
end if

End Sub

--------------------------------------------------------------------------------------------------------------------------------------------
0
 
Abiel de GrootCommented:
In the select case I forgot to put double commas round the city name. You need to do it as follows.
Case "barrie"
Case "calgary"


etc

0
 
gwendaellwoodAuthor Commented:
Thank you Jonbysoft. One last question: - if I move this code out of <HEAD> where should I put it? I just put it there because I didn't know any better.
0
 
gwendaellwoodAuthor Commented:
Thank you!
0
 
gwendaellwoodAuthor Commented:
Jonbysoft: I found the mail object i am using has a queue = true property - wow! THAT really helped too! Thx,G
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 5
  • 5
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now