When sending mail via SMTP, I get "Transport Failed to Connect to server"

I have the code below to send mail from a VBA macro using CDO. I get an error in the code:

Transport failed To connect to server Error

I am sending a mail from the Gmail SMTP service. Looks like the configuration is set correctly, but somehow it doesn't work.

Sub Email() Dim CDO_Mail As Object Dim CDO_Config As Object Dim SMTP_Config As Variant Dim strSubject As String Dim strFrom As String Dim strTo As String Dim strCc As String Dim strBcc As String Dim strBody As String strSubject = "Results from Excel Spreadsheet" strFrom = "[email protected]" strTo = "[email protected]" strBody = "The total results are: 167" Set CDO_Mail = CreateObject("CDO.Message") Set CDO_Config = CreateObject("CDO.Configuration") CDO_Config.Load -1 Set SMTP_Config = CDO_Config.Fields With SMTP_Config .Item("") = 2 .Item("") = "smtp.gmail.com" .Item("") = 1 .Item("") = "[email protected]" .Item("") = "xxxx" .Item("") = 465 .Item("") = True .Update End With With CDO_Mail Set .Configuration = CDO_Config End With CDO_Mail.Subject = strSubject CDO_Mail.From = strFrom CDO_Mail.To = strTo CDO_Mail.TextBody = strBody CDO_Mail.Send End Sub 
0

1 Answer

That code works totally fine for me (send from Gmail to Gmail) - so you need to check the following:

  • try it with port 587 as well as port 465 (further reading)
  • configure your sending account in Gmail for Access for less secure apps - there is a Turn On option per the following support page

Allowing less secure apps to access your account Google may block sign-in attempts from some apps or devices that do not use modern security standards. Since these apps and devices are easier to break into, blocking them helps keep your account safe.

Some examples of apps that do not support the latest security standards include:

The Mail app on your iPhone or iPad with iOS 6 or below

The Mail app on your Windows phone preceding the 8.1 release

Some Desktop mail clients like Microsoft Outlook and Mozilla Thunderbird

...

Option 2: Change your settings to allow less secure apps to access your account. We don't recommend this option because it might make it easier for someone to break into your account. If you want to allow access anyway, follow these steps:

Go to the "Less secure apps" section in My Account.

Next to "Access for less secure apps," select Turn on. (Note to Google Apps users: This setting is hidden if your administrator has locked less secure app account access.)

CDO is pretty old now so assume that is an example of an app that doesn't support latest security standards.

0

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like