【问题标题】:"The Transport Failed to Connect to the Server" when trying to send spreadsheet via SMTP尝试通过 SMTP 发送电子表格时出现“传输无法连接到服务器”
【发布时间】:2015-12-19 18:19:18
【问题描述】:

我正在尝试使用下面显示的代码通过 SMTP 发送 Excel 电子表格。但是,每当我运行代码时,我都会收到错误“传输无法连接到服务器”

代码如下:

    Sub CommandButton_Click()
Dim CDO_Mail_Object As Object
Dim CDO_Config As Object
Dim SMTP_Config As Variant
Dim Email_Subject, Email_Send_From, Email_Send_To, Email_Cc, Email_Bcc, Email_Body As String

Email_Subject = "Trying to send email using CDO"
Email_Send_From = "xxxxx@yahoo.com"
Email_Send_To = "xxxxx@hotmail.com"
Email_Cc = ""
Email_Bcc = ""
Email_Body = "Congratulations!!!! You have successfully sent an e-mail using CDO !!!!"

Set CDO_Mail_Object = CreateObject("CDO.Message")

On Error GoTo debugs
Set CDO_Config = CreateObject("CDO.Configuration")
CDO_Config.Load -1
Set SMTP_Config = CDO_Config.Fields
With SMTP_Config
'please put your server name below
.Item("http://schemas.Microsoft.Com/cdo/configuration/smtpusessl") = True
.Item("http://schemas.Microsoft.Com/cdo/configuration/smtpusetls") = True
.Item("http://schemas.Microsoft.Com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "xxxxx@yahoo.com"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "xxxxx"
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.mail.yahoo.co.uk"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
.Update
End With

With CDO_Mail_Object
Set .Configuration = CDO_Config
End With

CDO_Mail_Object.Subject = Email_Subject
CDO_Mail_Object.From = Email_Send_From
CDO_Mail_Object.To = Email_Send_To
CDO_Mail_Object.TextBody = Email_Body
CDO_Mail_Object.cc = Email_Cc 'Use if needed
CDO_Mail_Object.BCC = Email_Bcc 'Use if needed
'CDO_Mail_Object.AddAttachment FileToAttach 'Use if needed
CDO_Mail_Object.send

debugs:
If Err.Description <> "" Then MsgBox Err.Description
End Sub

上述代码中是否有错误(我已启用 Excel > 工具 > 参考中包含的 Microsoft CDO 库)或者我提供的 SMTP 凭据中是否有错误?
我是否使用了错误的 Yahoo SMTP 服务器(我应该使用 .com)吗?

【问题讨论】:

    标签: excel vba email smtp


    【解决方案1】:

    不知道这是否适用于您的情况,但我最近在类似的帖子中看到了这一点。

    尝试删除您的架构网址中的大写字母?

    “Microsoft.com”->“microsoft.com”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-03
      • 1970-01-01
      • 2016-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多