CDO.Message .Send causes script execution timeout

2019-06-07 00:51发布

问题:

I have the following code:

Set myMailanon = CreateObject("CDO.Message")
myMailanon.MimeFormatted = True

Set myConfanon = Server.CreateObject("CDO.Configuration")
Set objBPanon = myMailanon.AddRelatedBodyPart("http://www.foo.bar/img/logo1.jpg", "http://www.foo.bar/img/logo1.jpg", CdoReferenceTypeName)
objBPanon.Fields.Item("urn:schemas:mailheader:Content-ID") = "<http://www.foo.bar/img/logo1.jpg>" 
objBPanon.Fields.Update 
ConfURLanon = "http://schemas.microsoft.com/cdo/configuration/"

with myConfanon        
  .Fields.Item(ConfURLanon & "sendusing") = 2        
  .Fields.Item(ConfURLanon & "smtpserver") = "smtp.foo.bar"        
  .Fields.Item(ConfURLanon & "smtpserverport") = 25     
  .Fields.Item(ConfURLanon & "smtpusessl") = false
  .Fields.Item(ConfURLanon & "smtpauthenticate") = 1
  .Fields.Item(ConfURLanon & "sendusername") = "foo@bar.com"
  .Fields.Item(ConfURLanon & "sendpassword") = "foobarpass"
  .Fields.Update
end with

with myMailanon
  .Subject='Foo!! Bar!!'
  .From='Foo!! Bar!! <foo@bar.com>'      
  .To='foo@bar.com,bar@foo.com'      
  txt="This is foo... bar... text... SPARTAAAAAAAAA"
  .HTMLBody = txt
  Set .Configuration = myConfanon   
  On Error Resume Next 
  .Send      
end with

Problem is that this code, run 100 times, will work 30 and fail 70. Randomly. And by "fail" I mean that it will cause Script execution timeout.

After commenting line by line, I got to the conclusion that the error comes from ".Send". But why? Any ideas?

Regards

回答1:

There isn't anything wrong with code (athough CdoReferenceTypeName looks a little suspect but that could be just poor variable naming). It could just be that the SMTP server is busy and is therefore taking a while to process the send.

You could check the Script Time-out value specified for the ASP feature in IIS manager. By default it should be 90 seconds but perhaps its been set to a low value for some reason.

You can increase the amount of time you script has by specifying it in your code.

Server.ScriptTimeout = 300

Which would give your script a 5 minutes. This may well be masking some set up problem between your web server and SMTP server but it may increase the success rate. OTH you may get the same results but the 70% failures take longer to occur.

Whatever the cause I don't think its your code.