HMLHttp.SetTimeouts

Bob Schneider
Bob Schneider used Ask the Experts™
on
I am trying to send race results to race finishers in classic asp and my script keeps timing out.  I have my Server.ScriptTimeOut set plenty high.  (note that I just added the xmlhttp.SetTimeOuts)  Not sure if I have the other timeout set correctly.  Can someone look at the following code and let me know what changes might help please?  Thans!

Set cdoConfig = CreateObject("CDO.Configuration")
With cdoConfig.Fields
    .Item(cdoSendUsingMethod) = cdoSendUsingPort
    .Item(cdoSMTPServer) = "smtp.mandrillapp.com"
    .Item(cdoSMTPAuthenticate) = 1
    .Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 587
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
    .Item(cdoSendUsername) = "username"
    .Item(cdoSendPassword) = "pwd"
    .Update
End With

    bSentBCC = False

	For j = 0 To UBound(SendTo) - 1
		'get email address
		sMyEmail = vbNullString
				
		If DontSend(SendTo(j)) = False Then sMyEmail = SendTo(j)

		If Not sMyEmail = vbNullString Then
			If ValidEmail(sMyEmail) = True Then
                            
                sPageToSend = "http://www.gopherstateevents.com/misc/pix-vids_notif.asp?event_id=" & lEventID 

                Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
	                xmlhttp.open "GET", sPageToSend, false
                    xmlHttp.SetTimeouts 0, 60000, 300000, 300000
	                xmlhttp.send ""
	                EmailContents = xmlhttp.responseText
                Set xmlhttp = nothing

			    Set cdoMessage = CreateObject("CDO.Message")
			    With cdoMessage
				    Set .Configuration = cdoConfig
    				    .To = sMyEmail
				    .From = "bob.schneider@gopherstateevents.com"
                   		    .Subject = "Pictures Are Ready for " & sEventName
				    .HTMLBody = EmailContents
				    .Send
			    End With
			    Set cdoMessage = Nothing
		    End If
        End If
	Next

    Set cdoConfig = Nothing

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Developer & EE Moderator
Fellow 2018
Most Valuable Expert 2013
Commented:
What do you have the session time out set to?

How many records are in the database?

Where is is timing out and what is the specific error you are getting?

You really are best off sending this to a 3rd party smtp service like sendgrid.  Then it is just a matter of sending the data to the service and the service takes care of sending.  

Otherwise, try and separate sending out the email by placing it in a function so you can open and close the stmp server right away.

Also, don't try and send out more than 300 to 500 at a time and you really don't want to send out more than that in one hour or it can get flagged as spam by the receiving server.  You want to hit the sending page with a scheduled task. Use a new table in the db to track what is sent. Send out 500 and stop. Then use the new table to not send out the previous contacts.

By sending out 300 to 500 at a time, you will not have time out issues and you will also help get the emails to the inbox.  With that said, using a service  like sendgrid will help even more.
Scott FellDeveloper & EE Moderator
Fellow 2018
Most Valuable Expert 2013

Commented:
Bob, I just noticed you are using Mandrill. My bad for not catching that.  In this case, you may be getting an error back from Mandrill that is causing it to time out. Look at your Mandrill admin panel.

Also, they give you two options for sending, SMTP and the API. The API may be less likely to time out.  This is what I was referring to above.

Post here if you are still running into an issue.
Bob SchneiderCo-Owner

Author

Commented:
Thanks Scott!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial