CDO Error - transport failed to connect to the server

tanny81

Board Regular
Joined
Mar 2, 2006
Messages
175
Hi All,

I am currently trying to use CDO to send email messages as part of a program.

The code itself has come from here http://www.rondebruin.nl/cdo.htm and this is the actual code I am using (where ServerName is actually the name of the server I am using, and the To filed is a valid email address);

Code:
Sub test()


Dim iMsg As Object
Dim iConf As Object

    UserId = Environ("USERNAME")
    Set iMsg = CreateObject("CDO.Message")
    Set iConf = CreateObject("CDO.Configuration")

    iConf.Load -1
    
    Set Flds = iConf.Fields
    With Flds
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") ="ServerName"
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
        .Update
    End With


    With iMsg
    Set .Configuration = iConf
        .To = "tanny81@xyz.com"
        .CC = ""
        .BCC = ""
        .FROM = """Me"" <tanny81@xyz.com>"
        .Subject = "***TEST*** " & UserId
        .TextBody = ""
        .Send
    End With
            
End Sub

The problem I am having is that it will intermittingly error on the .Send line and give me a "transport failed to connect to the server" error message, none of the values in any of the fields change, it just fails more often than not. I have asked some colleagues to try this aswell, and they get the same result. Also while it is failing for me, it will work for somebody else & vice versa - frustrating as hell

I have tried out the suggestions outlined on the link provided above, aswell as other suggestions via google (ensuring the SMTP client is installed on the machine, adding the Microsoft CDO object reference, clearing the CDO Message's Configuration fields) all to no avail.

Does anybody else have any suggestions as to a way around this before I bite the bullet and have to use email client specific code?
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Forum statistics

Threads
1,224,566
Messages
6,179,558
Members
452,928
Latest member
101blockchains

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top