jceast7
jceast7

Reputation: 19

Send CDO email using Outlook through excel VBA code

I have code for emailing using CDO from internet - but I keep getting the message " The transport failed to connect to the server"

I have tried various setting changes for server exchange but no luck.

`````
strSubject = "Results from Excel Spreadsheet"
strFrom = "[email protected]"   '"[email protected]"
strTo = "[email protected]"     '"[email protected]"
strCc = ""
strBcc = ""
strBody = "The total results for this quarter are: "   '& Str

'STEP 3
'The next section of code is where you will configure CDO to use any
 external SMTP server to send the email.


Set CDO_Mail = CreateObject("CDO.Message")
On Error GoTo Error_Handling

Set CDO_Config = CreateObject("CDO.Configuration")
CDO_Config.Load -1

Set SMTP_Config = CDO_Config.Fields

With SMTP_Config
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")
= "Microsoft Exchange"  '"smtp.hotmail.com"   '"smtp.gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")
= 1
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername")
= "[email protected]"     '"[email protected]"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword")
= "123456"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") 
= 25
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Update
End With

With CDO_Mail
Set .Configuration = CDO_Config
End With
``````

Upvotes: 0

Views: 1698

Answers (1)

Ronan Vico
Ronan Vico

Reputation: 605

 " The transport failed to connect to the server"

That error means that u need to login in your account on website (Google or whatever) and select "Allow external progams to use the email" (something like that) , it worked for me , I was in the same place as you!

Upvotes: 2

Related Questions