Link to home
Start Free TrialLog in
Avatar of HKFuey
HKFueyFlag for United Kingdom of Great Britain and Northern Ireland

asked on

VBA Office 365 "The transport failed to connect to server"

VBA Send Mail using Office 365

Followed this article https://www.tachytelic.net/2018/12/email-vbscript-vba-office-365/

Dim objMessage, objConfig, Fields
Set objMessage = CreateObject("CDO.Message")
Set objConfig = CreateObject("CDO.Configuration")
Set Fields = objConfig.Fields

With Fields
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.office365.com"
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = "587"
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "xxxxx@xxxxx"
        .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "xxxxxx"
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
        .Update

End With
    
Set objMessage.Configuration = objConfig
    
    With objMessage
 
        .Subject = "Test Msg"
        .from = "x@xcom"
        .To = "y@gmail.com"

        
objMessage.Send
        
    DoCmd.Close
    End With

Open in new window


Getting  "The transport failed to connect to server" Can anyone help?
Avatar of Bill Prew
Bill Prew

Well, I had some test code that I had built 2 years ago and looks very similar to yours.  The big difference was I had to use port 25 at the time to get it to work as I recall.  Trying that today though it no longer works, I have the same error you are.  I tried several different combinations of ports and security modes but none seemed to work.

One obvious thing you need to determine is that your organization or internet ISP does not block outgoing connections on port 25 ot 587.  Some do that.

Beyond that I did find these two posts that you may want to follow up on, they weren't enough for me to be able to figure out a working solution.

Sorry I don't have more to offer, if you get it working be sure and post back here.



»bp
ASKER CERTIFIED SOLUTION
Avatar of HKFuey
HKFuey
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of HKFuey

ASKER

Thanks for your input
Glad you got that to work.


»bp