vbscript - CDO.消息 - "The transport failed to connect to the server."

标签 vbscript asp-classic

我正在开发一个使用 CDO.Message 在函数中发送电子邮件的经典 ASP 和 Vbscript 站点。我在使用此功能时遇到了问题,并收到错误消息,

CDO.Message.1 error '80040213'

The transport failed to connect to the server.

我认为这与 SMTP 身份验证设置和我们运行的共享主机有关。我正在寻求进一步调试问题的帮助。

这是函数的主要代码片段,

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 行的注释,但似乎以前的开发人员故意对它们进行了注释,并且电子邮件功能在某个时间点仍然有效。取消注释这些行仍然不能解决错误。

任何人都可以看到我可能遗漏的任何东西吗?有谁知道 CDO.Configuration 的默认值是什么以及此代码试图与我们的共享主机一起使用的 SMTP 设置?我应该先调用我们的主机并向他们澄清吗?

最佳答案

在我将类型库包含在 asp 页面的顶部之前,我在使用 CDO 时遇到了困难。请注意,类型库不在 <% %> 分隔符内。 typelib 行很长,因此您需要向右滚动才能全部阅读

首先尝试将 typelib 语句添加到您的页面。

如果这不起作用,请尝试下面的其余代码。我已在 Godaddy 托管的我的网站上成功使用此代码。当然,如果需要,您必须输入邮件服务器信息和登录名/密码。

<!--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
%>

关于vbscript - CDO.消息 - "The transport failed to connect to the server.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1814553/

相关文章:

xml - 经典 ASP .loadXML(XMLstring) 读出空白?

asp-classic - VBScript VarType 函数给出奇怪的值

html - 如何在 HTML 中使用 css 打印 A4 尺寸的纸张(使用经典的 ASP)

asp.net - 我们讨厌经典 asp 但今天仍然存在于 web 表单中的东西

asp-classic - 经典ASP响应状态500

excel - 在vbscript中将txt文件转换为excel

vbscript - 如何在vbscript中提供信息符号?

javascript - 如何在 Enterprise Architect 中将公共(public)表中的列添加到新表

visual-studio-2010 - 尽管字符集正确,德语元音仍显示错误

asp-classic - 如果 ASP 页意外退出,Connection 事务会发生什么情况?