cancel
Showing results for 
Search instead for 
Did you mean: 

CDOSYS error '80040213' - failed to connect to server

chenks76
All Star
Posts: 3,274
Thanks: 338
Fixes: 12
Registered: ‎24-10-2013

CDOSYS error '80040213' - failed to connect to server

does anyone here have any experience of classic ASP and CDOSYS email?

i posted this over on stackoverflow, but so far not having any luck

 

I have a Windows Server 2003 R2 running IIS and a website using classic ASP. Trying to get it to use CDOSYS to email using our own (externally) hosted office365 exchange server.

I get the following error

CDO.Message.1 error '80040213'
The transport failed to connect to the server.

Which usually means one of 3 problems: 1. Incorrect SMTP server / port 2. Incorrect login/password 3. FROM address not valid according to SMTP server (wrong domain)

The SMTP server and port are correct according to supplier. The login/password is correct as I can log into the mail account using those details The FROM address is correct as that is the account I am using to log in.

I can telnet to the exchange server from the web server on that address and port, so a connection can be made from the server at least.

So at the moment I'm at a loss as to what the problem might be. Does anyone have any pointers as to anything else I need to look at?

This is the config the website is using

myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing")=2 
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.office365.com"
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=587
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 20
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "username"
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
9 REPLIES 9
Anonymous
Not applicable

Re: CDOSYS error '80040213' - failed to connect to server

I have to ask @chenks76 but I assume you are calling the Update Method prior to execution?

myMail.Configuration.Fields.Update

Also, have you tried extending the connection timeout?

chenks76
All Star
Posts: 3,274
Thanks: 338
Fixes: 12
Registered: ‎24-10-2013

Re: CDOSYS error '80040213' - failed to connect to server

this is the full script

Set myMail=CreateObject("CDO.Message")
myMail.Subject="TEST"
myMail.To="*****@*****.co.uk"
myMail.TextBody="TEST"

myMail.From="*****@*****.co.uk"
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing")=2 
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.office365.com"
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=587
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "*****@*****.co.uk"
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "PASSWORD"

myMail.Configuration.Fields.Update
myMail.Send
set myMail=nothing

the timeout makes no difference, as it's an instant fail.

 

Anonymous
Not applicable

Re: CDOSYS error '80040213' - failed to connect to server

Well it looks quite sane to me, have you tried to send a plain email using something like this:

Set myMail = CreateObject("CDO.Message")
myMail.Subject = “Test eMail CDO“
myMail.From = “sender@domain”
myMail.To = “recipient@domain”
myMail.TextBody = "This is a test message"
On Error Resume Next
myMail.Send
If Err.Number > 0 Then
   Output Err.Description Here
End If
set myMail = Nothing

If this works try turning off SSL to see if that changes anything.

Anonymous
Not applicable

Re: CDOSYS error '80040213' - failed to connect to server

@chenks76 - You said you can telnet in to the server but you may want to verify the SSL side of the connection; so if you have access to a Linux / Mac CLI with OpenSSL installed, you can try this, using your email address and password:

echo -ne ‘\0address@domain.co.uk\0password’ | base64

This will output a base64 encoded string to the console, you’ll need this later. Now execute this:

openssl s_client -connect smtp.office365.com:587 -starttls smtp

When you’re connected you should see a 250 response, so enter

EHLO there

This will print the verbs supported by the server, the one you’d be interested in is ‘AUTH PLAIN LOGIN’

If you see this in the response list use :

AUTH PLAIN PasteBase64Here

Assuming all is well you should see a 235 response code. So enter:

quit

to exit.

 

chenks76
All Star
Posts: 3,274
Thanks: 338
Fixes: 12
Registered: ‎24-10-2013

Re: CDOSYS error '80040213' - failed to connect to server

i only have access to the Windows 2003 R2 web server.
Anonymous
Not applicable

Re: CDOSYS error '80040213' - failed to connect to server

Bummer about the SSL, so what about the outcome of a plain text send test?

chenks76
All Star
Posts: 3,274
Thanks: 338
Fixes: 12
Registered: ‎24-10-2013

Re: CDOSYS error '80040213' - failed to connect to server

how do i attempt a plan text send?
the office365 server only allows connections based on the parameters that are already attempting to be used.

i'm leaning towards this being an issue with the web server rather than the SMTP server, however i have nothing to base this on really.
Anonymous
Not applicable

Re: CDOSYS error '80040213' - failed to connect to server

You send a plain text mail using the code from message 4 with the Form and To fields completed with proper addresses, ideally it would be best to send it to yourself using the same From and To.

It’s not going through your mail server but will be sent locally using the CDO which is why the pseudo ASP is so minimal.

chenks76
All Star
Posts: 3,274
Thanks: 338
Fixes: 12
Registered: ‎24-10-2013

Re: CDOSYS error '80040213' - failed to connect to server

just tried that and nothing happens.
no email is received, no error either