【问题标题】:Sending an Outlook email when the Computer is locked计算机锁定时发送 Outlook 电子邮件
【发布时间】:2016-10-12 00:05:38
【问题描述】:

当计算机被锁定时,我想发送一封包含 Excel 工作表范围的 Outlook 电子邮件

我正在使用 ODBC 连接运行每周刷新的仪表板。我写了一个在 auto_open 上运行的宏。该文件由任务计划程序打开。

系统: 视窗 7 SP1, 展望 2016, Excel 2016

问题:当我将任务设置为运行时,无论用户是否登录,Excel 文件都会打开并刷新,但它不会发送邮件,也不会出现在我的发件箱中。刷新确实发生了。 这是用户没有登录的时候。我的意思是计算机被锁定了。

当用户登录时任务计划工作正常

我已经尝试过这个Excel VBA - Email Does not Send When Computer is Locked,但它对我不起作用。

我用来发送邮件的功能是:

Dim oApp As Object, OutApp As Object, OutMail As Object
Dim rng As Range
Dim strbody As String, strtail As String

strbody = "Hi team," & "<br>" & _
         "<a href=""https://example.com"">Here</a> is the link to cloud upload" & Worksheets("Core View").Range("M2") & "<br><br>"
strtail = "Thanks," & "<br>" & _
"Team." & "<br><br>"

On Error Resume Next
'Only the visible cells in the selection
'Set rng = Selection.SpecialCells(xlCellTypeVisible)
Set rng = Sheets("Core View").Range("A7:K106").SpecialCells(xlCellTypeVisible)
On Error GoTo 0


If rng Is Nothing Then
    MsgBox "The selection is not a range or the sheet is protected. " & _
      vbNewLine & "Please correct and try again.", vbOKOnly
End If

With Application
    .EnableEvents = False
    .ScreenUpdating = False
End With


'Create the mail
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

On Error Resume Next
With OutMail
    .To = "plaknas@example.com"
    .CC = ""
    .BCC = ""
    If EmptySheets <> "" Then
        .Subject = "update has issues in " & EmptySheets
    Else
        .Subject = "Update for week" & Worksheets("Core View").Range("M2")
    End If
    .HTMLBody = strbody & RangetoHTML(rng) & strtail
    .Send   'or use .Display
End With
On Error GoTo 0
With Application
    .EnableEvents = True
    .ScreenUpdating = True
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Function

【问题讨论】:

  • 当没有用户登录时,没有 Outlook 帐户可以访问以发送邮件。我不希望任何东西都能抓住 Outlook 并开始倾销电子邮件 - 你会吗?这就是恶意软件过去通常的行为方式,这正是 Outlook 现在不允许这样做的原因。
  • @KenWhite 很抱歉,但我的意思是计算机被锁定,当我写“这是用户未登录时”。不过,你说的有道理。让我吃惊的是,它在电脑未锁定的情况下也能正常工作。
  • 我所说的适用于用户未登录的情况,我理解您的意思是这是用户未登录的情况。 :-)

标签: excel vba outlook scheduled-tasks


【解决方案1】:

您不能在从任务计划程序运行或作为 Windows 服务运行的脚本或程序中使用 Outlook 对象模型。安全上下文完全不同,代码不会按预期运行:

https://support.microsoft.com/en-us/kb/237913

【讨论】:

  • 非常感谢@ericlegault。几天来一直在寻找这个确切的文档
  • 不客气!我也不得不寻找这个,很多链接都被破坏了,即使搜索文章标题
猜你喜欢
  • 2012-04-29
  • 2010-09-25
  • 2017-06-11
  • 1970-01-01
  • 2018-07-24
  • 1970-01-01
  • 2015-05-03
  • 1970-01-01
相关资源
最近更新 更多