通过SMTP发送邮件时,我收到“传输无法连接到服务器"消息. [英] When sending mail via SMTP, I get "Transport Failed to Connect to server"

查看:635
本文介绍了通过SMTP发送邮件时,我收到“传输无法连接到服务器"消息.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下面的代码使用CDO从VBA宏发送邮件.我在代码中收到错误:

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

我正在从Gmail SMTP服务发送邮件.看起来配置已正确设置,但是以某种方式无法正常工作.

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 = "xxx@gmail.com"
    strTo = "xxx@gmail.com"
    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("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
      .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
      .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
      .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "xxxx@gmail.com"
      .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "xxxx"
      .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
      .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 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

推荐答案

该代码对我来说很好用(将 Gmail 发送到 Gmail)-因此,您需要检查以下内容:

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

  • 尝试使用端口587和465(进一步阅读)
  • 在Gmail中配置您的发送帐户,以使用访问安全性较差的应用-根据以下
  • 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

允许安全性较低的应用访问您的帐户Google可能会阻止某些未使用现代安全标准的应用或设备的登录尝试.由于这些应用程序和设备更容易被破解,因此屏蔽它们可以确保您的帐户安全.

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:

在装有iOS 6或更低版本的iPhone或iPad上的Mail应用

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

8.1之前版本的Windows手机上的Mail应用

The Mail app on your Windows phone preceding the 8.1 release

某些桌面邮件客户端,例如Microsoft Outlook和Mozilla Thunderbird

Some Desktop mail clients like Microsoft Outlook and Mozilla Thunderbird

...

选项2:更改设置,以允许安全性较差的应用访问您的帐户.我们不建议您使用此选项,因为它可能使某人更容易进入您的帐户.如果仍然要允许访问,请按照以下步骤操作:

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:

转到我的帐户"中的安全应用程序较少"部分.

在访问不太安全的应用程序"旁边,选择打开.(对Google Apps用户的注意:如果您的管理员锁定了不太安全的应用程序帐户访问权限,则此设置将隐藏.)

CDO 很老了现在,假设这是不支持最新安全标准的应用示例.

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

这篇关于通过SMTP发送邮件时,我收到“传输无法连接到服务器"消息.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆