CDO.Message-“传输未能连接到服务器." [英] CDO.Message - "The transport failed to connect to the server."
问题描述
我正在开发经典ASP&使用CDO.Message在功能中发送电子邮件的Vbscript站点.我在使用此功能时遇到了麻烦,并且正在收到错误消息,
I'm working on a Classic ASP & Vbscript site that uses CDO.Message to send email in a function. I'm running into trouble with this function and am recieving the error,
CDO.Message.1 error '80040213'
The transport failed to connect to the server.
我认为这与SMTP身份验证设置和我们正在运行的共享主机有关.我正在寻找进一步调试该问题的帮助.
I believe it has to do with the SMTP authentication settings and the shared host we are running on. I am looking for help debugging the issue further.
这是该函数的主要代码段,
Here is the main code snippet from the function,
Set objConfig = Server.CreateObject("CDO.Configuration")
Set Fields = objConfig.Fields
' Set config fields we care about
With Fields
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = "mail.<website>.com"
'.Item(cdoSMTPServerPort) = 25
'.Item(cdoSMTPConnectionTimeout) = 10
'.Item(cdoSMTPAuthenticate) = cdoBasic
'.Item(cdoSendUserName) = "support"
'.Item(cdoSendPassword) = "password"
.Update
End With
Set objMessage = Server.CreateObject("CDO.Message")
Set objMessage.Configuration = objConfig
With objMessage
.To = lEmailTo '"Display Name <email_address>"
.From = lEmailFrom '"Display Name <email_address>"
.Subject = lSubject
.TextBody = lMessage
.Send
End With
起初,我认为上面的代码段中可能包含9-13行,但是似乎以前的开发人员故意对此进行了注释,并且电子邮件功能在某个时间点仍在起作用.取消注释这些行仍不能解决该错误.
At first I believed it might have been with the commented lines 9-13 in the above snippet, but it appears that a previous developer commented them on purpose and that the email function was still working at some point in time. Uncommenting those lines still doesn't solve the error.
有人可以看到我可能会想念的东西吗?有谁知道CDO.Configuration的默认设置是什么以及此代码试图与我们的共享主机一起使用的SMTP设置吗?我应该先打电话给我们的托管和托管吗?与他们澄清?
Can anyone see anything I might be missing? Does anyone know what the defaults for CDO.Configuration are and what SMTP settings this code is trying to use with our shared host? Should I first call our hosting & clarify with them?
推荐答案
在使用CDO之前,我遇到了一段艰难的时期,直到我将asplib放在了ASP页面的顶部.请注意,typelib不在<%%>分隔符内. typelib行很长,因此您需要向右滚动以阅读所有内容
I had a difficult time with CDO until I included the typelib at the top of the asp page. Notice that the typelib is not inside the <% %> delimiters. The typelib line is quite long so you need to scroll right to read it all
首先尝试仅将typelib语句添加到您的页面.
Try adding just the typelib statement to your page first.
如果这不起作用,请尝试下面的其余代码.我已经在Godaddy托管的网站上成功使用了此代码.当然,如果需要,您必须插入邮件服务器信息和登录名/密码.
If that doesn't work then try the rest of the code below. I have successfully used this code on my websites hosted by Godaddy. Of course you'll have to plug in your mail server info and login/password if needed.
<!--METADATA TYPE="typelib" UUID="CD000000-8B95-11D1-82DB-00C04FB1625D" NAME="CDO for Windows 2000 Type Library" -->
<%
Sub SendEmail()
Set cdoConfig = CreateObject("CDO.Configuration")
if lcase(Request.ServerVariables("SERVER_NAME")) = "dev" then
With cdoConfig.Fields
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = "xxx.<devmailservername>.xxx"
.Item(cdoSMTPAuthenticate) = 1
.Item(cdoSendUsername) = "xxxxxxxx@yyyyyyyyy.com"
.Item(cdoSendPassword) = "<passwordgoeshere>"
.Update
End With
else
With cdoConfig.Fields
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = "xxx.<productionmailservername>.xxx"
.Update
End With
end if
Set cdoMessage = CreateObject("CDO.Message")
With cdoMessage
Set .Configuration = cdoConfig
.From = "xxxxxxx@yyyyyyyy.com"
.To = "yyyyyyyy@zzzzzzzzz.com"
.Subject = "Sample CDO Message"
.htmlbody = "<html><body>Sample <b>CDO</b> message.</body></html>"
.TextBody = "Sample CDO Message."
.Send
End With
Set cdoMessage = Nothing
Set cdoConfig = Nothing
End Sub
%>
这篇关于CDO.Message-“传输未能连接到服务器."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!