CDO.Message - “The transport failed to connect to the server.”

爱⌒轻易说出口 提交于 2019-12-10 18:30:33

问题


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.

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

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.

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?


回答1:


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

Try adding just the typelib statement to your page first.

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



回答2:


I changed the cdoSMTPServer to localhost, all ship shape!



来源:https://stackoverflow.com/questions/1814553/cdo-message-the-transport-failed-to-connect-to-the-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!