简体   繁体   English

CDO.Message .Send导致脚本执行超时

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

相关问题 来自CDO.Message发送方法的未知电子邮件代码 - Unknown email code from CDO.Message send method Excel VBA-通过CDO.message发送电子邮件-无法添加附件 - Excel VBA - Send Email via CDO.message - cannot add attachment CDO.Message和System.Net.Mail之间的区别 - Difference between CDO.Message and System.Net.Mail 修改CDO.Message对象中附件的内容类型 - Modifying the content type of an attachment in a CDO.Message object 了解Microsoft的CDO.Message脱机行为 - Understanding Microsoft's CDO.Message offline behavior CDO.Message Email 来自 VBA 中的 Office 365 帐户 - CDO.Message Email from Office 365 Account in VBA 是否可以使用SQL数据库邮件通过URL通过HTML页面发送HTML页面,就像在VBScript中使用CDO.Message对象一样? - Can I use SQL Database Mail to send an HTML page as a message via its URL, the same way you can with the CDO.Message object in VBScript? 使用 CDO.Message 发送电子邮件 - 发送到外部地址时失败 - sending email using CDO.Message - fails when sending to external address 设置CDO.Message选项时使用的f(x)= y JScript惯用语的JavaScript友好替代方法 - JavaScript-friendly alternative to the f(x) = y JScript idiom that's used when setting CDO.Message options SmtpClient.Send将发送消息AND超时 - SmtpClient.Send will send a message AND timeout
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM