【问题标题】:How to send mail when the .Send does not work?.Send 不起作用时如何发送邮件?
【发布时间】:2018-06-14 17:30:19
【问题描述】:

我正在尝试通过 VBA 发送电子邮件。

当 .Send 不起作用时,我发现 Sendkeys 方法有效,但电子邮件必须显示,然后您无法触摸计算机,否则您可能会破坏宏。

如何使 .Send 方法起作用?

    Dim OutApp As Object
    Dim OutMail As Object
    Dim count As Integer

    EmailTo = Worksheets("Email Addresses").Range("A2")

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItemFromTemplate( _
    Sheets("Start Here").Range("B25"))

    On Error Resume Next
    With OutMail

        .To = EmailTo
        '.CC = ""
        '.BCC = ""
        '.Subject = ""
        '.Body = ""
        '.Attachments.Ad' ActiveWorkbook.FullName
        ' You can add other files by uncommenting the following line.
        '.Attachments.Add ("C:\test.txt")
        ' In place of the following statement, you can use ".Display" to
        ' display the mail.
        '.Display
        'SendKeys "^{ENTER}" ' <---this was the fix I found when .Send didn't work
        .Send

    End With
    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing

【问题讨论】:

  • “当 .Send 不起作用时” - .Send 以什么方式不起作用?删除 On Error Resume Next 并查看产生了哪些错误 - 这可能有助于使其正常工作。
  • 您的电子邮件安全设置是最有可能导致问题的原因。在 Outlook>>文件选项卡>>选项>>信任中心>>信任中心设置>>程序访问。
  • 根据 IT 部门的说法,根据@Sorceri 所说,您可能会也可能无法更改这些设置。例如,在我现在的工作中,我只能自动显示电子邮件,但不能通过代码发送。网络安全团队不允许这样做。
  • 谢谢大家,我的信任中心设置无法更改,所以这也是这里的原因。谢谢!
  • .Display 然后.Send 怎么样?

标签: excel vba email outlook


【解决方案1】:

您的电子邮件安全设置是最有可能导致问题的原因。在 Outlook>>文件选项卡>>选项>>信任中心>>信任中心设置>>程序访问。 – 巫师 1 小时前

根据 IT 部门的说法,根据 @Sorceri 所说,您可能无法更改这些设置,也可能无法更改。例如,在我现在的工作中,我只能自动显示电子邮件,但不能通过代码发送。网络安全团队不允许这样做。 – Scott Holtzman 56 分钟前

因此看来,SendKeys 是最佳选择,因为由我的 IT 部门控制的安全设置已将我锁定在信任设置中的编程访问之外。

感谢@Sorceri 和@Scott Holtzman

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-07
    • 2015-03-20
    • 2014-08-25
    • 2017-12-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多