[英]CDO.Message .Send causes script execution timeout
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. 问题在于,该代码运行100次,可以工作30次,但失败70次。是随机的。 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". 在逐行注释之后,我得出的结论是错误来自“ .Send”。 But why?
但为什么? Any ideas?
有任何想法吗?
Regards 问候
There isn't anything wrong with code (athough CdoReferenceTypeName
looks a little suspect but that could be just poor variable naming). 代码没有任何问题(尽管
CdoReferenceTypeName
看起来有点可疑,但这可能只是变量命名不佳)。 It could just be that the SMTP server is busy and is therefore taking a while to process the send. 可能是SMTP服务器正忙,因此需要一些时间来处理发送。
You could check the Script Time-out value specified for the ASP feature in IIS manager. 您可以检查为IIS管理器中的ASP功能指定的脚本超时值。 By default it should be 90 seconds but perhaps its been set to a low value for some reason.
默认情况下,它应该为90秒,但出于某种原因,也许将其设置为较低的值。
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. 这将使您的脚本有5分钟的时间。 This may well be masking some set up problem between your web server and SMTP server but it may increase the success rate.
这很可能掩盖了Web服务器和SMTP服务器之间的某些设置问题,但可能会提高成功率。 OTH you may get the same results but the 70% failures take longer to occur.
另外,您可能会得到相同的结果,但70%的故障会花费更长的时间。
Whatever the cause I don't think its your code. 不管是什么原因,我都不认为这是您的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.