【问题标题】:CDO.Message - "The transport failed to connect to the server."CDO.Message -“传输无法连接到服务器。”
【发布时间】:2019-03-25 22:44:58
【问题描述】:

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

CDO.Message.1 error '80040213'

The transport failed to connect to the server.

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

这里是函数的主要代码sn-p,

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

起初我认为它可能与上述 sn-p 中的注释行 9-13 相同,但似乎以前的开发人员故意对它们进行了注释,并且电子邮件功能在某个时间点仍然有效。取消注释这些行仍然不能解决错误。

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

【问题讨论】:

  • 暗示这段代码在“某个时候”工作,但现在不是。当它停止工作时发生了什么变化?
  • 我认为这是因为我们使用的共享主机发生了变化。尽管如此,你让我再次思考这个问题,现在它已经解决了!

标签: vbscript asp-classic


【解决方案1】:

在我将 typelib 包含在 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
%>

【讨论】:

    【解决方案2】:

    我将 cdoSMTPServer 更改为 localhost,一切正常!

    【讨论】:

      猜你喜欢
      • 2017-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-18
      • 1970-01-01
      • 2014-09-07
      • 1970-01-01
      • 2019-10-08
      相关资源
      最近更新 更多