Reputation: 25
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?
Upvotes: 3
Views: 65184
Reputation: 5184
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) = "[email protected]"
.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 = "[email protected]"
.To = "[email protected]"
.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
%>
Upvotes: 1