gpt4 book ai didi

vbscript - 从 VBScript 发送 Outlook 邮件时如何避免 Outlook 安全警报?

转载 作者:行者123 更新时间:2023-12-03 06:25:42 26 4
gpt4 key购买 nike

我有这样的情况:

  • 代码必须采用VBScript(超出我的控制范围)
  • 无法在 Outlook 偏好设置中禁用编程访问限制(组策略,而非管理员,并且 Windows 无法识别已安装的有效病毒扫描程序)
  • 无法使用 SMTP,因为它是不允许的。

我认为无法以自动化的方式使用 Outlook 发送电子邮件(在以屏幕锁定的用户身份登录的无人值守的盒子上)。我尝试了许多不同的方法,但总是收到安全警告消息。我该如何解决这个问题?

我已经尝试了 this 上的所有内容有用的网站并删除了每个选项,如下所示:

Strategies
Ideally, applications that automate Outlook should avoid code that triggers these security prompts.

正是我最终所做的(请参阅下面的答案),这就是为什么该页面上的所有其他选项都不相关的原因。让我们一一来看:

Sending messages
It is not necessary to use Outlook objects at all if your goal is simply to create and send an email message. Microsoft provides the CDO for Windows library for creating and sending messages with SMTP. Using this library totally bypasses Outlook and MAPI and does not trigger security prompts. For code samples, see ...

SMTP。不许去。网络策略不允许。

Use Extended MAPI instead of Outlook objects, Simple MAPI, or CDO 1.21 for all code that potentially triggers security prompts.

扩展 MAPI 可能有效,但它非常麻烦和冗长,并且涉及大量 C/C++ 代码(这不是这个问题的主题;见上文),并且似乎不可能在不提示用户的情况下使用它他们的密码。

Use a third-party library -- Redemption or MAPI33 -- for all code that potentially triggers security prompts. This approach is easier than using Extended MAPI, which has a steep learning curve, and almost as secure. These libraries also offer additional features to help with Outlook code projects.

第三方库的问题有四个方面: - 它们需要花钱; - 即使它们是免费的,它们也会引入许可问题(一些组织在允许软件进入生态系统之前需要经过律师的广泛审查); - 在大多数环境中,用户无法禁用 Outlook 选项中的编程访问警告,甚至会引发整个问题。嗯,那些可能的情况是什么?难道是……公司环境?在企业环境中采购软件需要花费太长的时间,以至于不切实际,除非使用它节省的成本超过数百万美元。但是,可以进行许多实际的流程改进,这些改进不会带来很高的成本节省,但如果需要软件采购,则采购第三方软件所花费的金钱和劳动力会比节省的总成本更多。 - 网络管理员可能不信任该软件驻留在系统上,因为它可能被用于恶意目的。

Deploy with your application a tool to suppress the security prompts.

这假设有必要抑制 OMG 提示,但就我而言,并非如此,只是为了发送一封简单的电子邮件(请参阅我的答案)。

For Outlook 2007, make sure the machine is running an up-to-date anti-virus application and do all coding with Outlook objects, avoiding CDO 1.21 and Simple MAPI code.

病毒扫描程序是最新的,但更改其版本或供应商完全超出我的控制范围,而且 Outlook 无法识别它。它显示:“防病毒状态:无效。此版本的 Windows 支持防病毒检测,但未找到防病毒。”

In Outlook custom form code, Outlook VBA code, and COM add-ins, derive all objects from the Outlook.Application object provided by VBA or the add-in architecture. For example, see the sample VBA "run a script" rule procedure below.

有趣,可能有用,但不是必需的。这会不必要地依赖于在 Outlook 中设置规则来部署软件,从而使部署变得复杂。

Deploy Outlook security settings that "trust" certain COM add-ins or that allow all applications to have unrestricted access to certain features, such as accessing addresses. In versions before Outlook 2007, this requires Microsoft Exchange Server. For Outlook 2007, see the section on version-specific considerations below.

麻烦:安装 COM 加载项需要管理访问权限,而在某些组织中可能很难获得管理访问权限。

In a corporate environment where Exchange is the email server, direct access to the data on the server is available through the WebDAV API beginning with Exchange 2000 and, starting with Exchange 2007, through Exchange Web Services.

在我的环境以及其他可能的环境中被禁用。

In a corporate environment, the administrator may choose to loosen Outlook security for some or all users.

当然,但这需要与网络团队沟通/协调/合作。如果管理访问权限不可用于安装 COM 插件,那么它也可能不可用于放松组策略。

最佳答案

此代码适用于我的 Outlook 2010 系统,无需用户交互即可发送电子邮件。它有点脆弱,因为如果用户在撰写邮件时恰好在系统上积极工作(打字、单击),则可能会出现用户输入进入弹出窗口的情况瞬间,要么干扰邮件的发送,要么在邮件正文中添加额外的未知字符。

只要运行此功能的系统的用户意识到这一点,并且虚假击键干扰的潜在后果不是业务关键型,则此功能是可以接受的。

需要注意的是:此解决方案的关键是我们不调用 MailItem.Send 方法。这是触发编程访问保护的方法。相反,我们触发 ALT+s 快捷方式,默认情况下,当邮件窗口在 Outlook 中获得焦点时,会按下“发送”按钮。如果您启用了默认的拼写检查提示,则会弹出进一步的拼写检查提示。我们的解决方案是禁用拼写检查提示,尽管我确信您可以添加更多 SendKeys 来单击它,因为拼写检查提示不是与安全相关的对话框。

关于 UIPI(用户界面权限隔离)的说明:

Outlook 2010 以登录系统的用户身份运行,完整性级别为。由 Windows 资源管理器启动的程序,或者作为以类似方式启动的程序的子程序或后代启动的程序,也将以完整性级别启动。只要用户和 session ID 匹配,并且完整性级别相同或更高,UIPI 就不能有效阻止“SendKeys”类型输入。在我的特定环境中,VBScript 主机进程和 Outlook 进程的用户和 session ID 相同,完整性级别相同。在您的环境中,如果其中任何条件不成立,则此代码将无法工作。它也未在 2010 版之前或更高版本的 Office 上进行测试。

Sub SendEmail_Outlook()
Set WshShell = WScript.CreateObject("WScript.Shell")
Set ol=CreateObject("Outlook.Application")
Set Mail=ol.CreateItem(0)
Mail.to= "you@example.com"
Mail.Subject = "test"
Mail.HTMLBody = "test"
Mail.Display
WshShell.SendKeys "%s"
Set Mail = Nothing
Set ol = Nothing
End Sub

SendEmail_Outlook

此外,还介绍了如何在从 Windows 任务计划程序运行 VBScript 时实现此功能。只需勾选红色椭圆形“以最高权限运行”框,即可使其以尽可能高的完整性级别运行,而无需 UAC 提升(如果您不是管理员帐户,则为“中”)。

windows task scheduler properties

关于vbscript - 从 VBScript 发送 Outlook 邮件时如何避免 Outlook 安全警报?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14898756/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com