通过Excel VBA代码使用Outlook发送CDO电子邮件

时间:2019-04-28 19:25:38

标签: excel vba outlook

我有使用Internet上的CDO发送电子邮件的代码-但我不断收到消息“传输无法连接到服务器”

我为服务器交换尝试了各种设置更改,但没有运气。

`````
strSubject = "Results from Excel Spreadsheet"
strFrom = "jceast7@hotmail.com"   '"rdube02@gmail.com"
strTo = "jceast7@hotmail.com"     '"rdube02@gmail.com"
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")
= "jceast7@hotmail.com"     '"email@website.com"
.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
``````

1 个答案:

答案 0 :(得分:2)

 " The transport failed to connect to the server"

该错误表示您需要在网站(Google或其他任何网站)上登录您的帐户 并选择“允许外部程序使用电子邮件”(类似方法),它对我有用,我和您在同一地方!