温馨提示:本文翻译自stackoverflow.com,查看原文请点击:其他 - Create New Outlook 365 Email in PowerShell
email office365 outlook powershell

其他 - 在PowerShell中创建新的Outlook 365电子邮件

发布于 2020-04-15 22:48:25

我正在尝试在PowerShell中创建Outlook电子邮件,并且到处都找到了相同的代码:

$ol = New-Object -comObject Outlook.Application

$mail = $ol.CreateItem(0)
$mail.Subject = "<Subject>"
$mail.Body = "<Body>"

然后

$inspector = $mail.GetInspector
$inspector.Display()

要么

$mail.Display()

显示电子邮件。

但是,在第一行我得到这个错误:

New-Object : Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).

我尝试了不使用-comObject并得到另一个错误:

New-Object : Cannot find type [Outlook.Application]: verify that the assembly containing this type is loaded.

我想用加载程序集

[Reflection.Assembly]::LoadWithPartialname("Microsoft.Office.Interop.Outlook") | out-null

但是在运行前面的命令时仍然会收到相同的错误消息。

万一有问题,我们正在使用Office 365,但我确实安装了Office的本地副本。我需要在Office 365中使用其他类型的对象吗?

同样,它似乎正在尝试与服务器建立对象。我有办法强迫它在本地这样做吗?

查看更多

提问者
Randy
被浏览
55
Dmitry Streblechenko 2020-02-04 06:24

CO_E_SERVER_EXEC_FAILURE表示Outlook在与应用程序不同的安全性上下文中运行。COM系统拒绝封送运行在不同安全上下文中的进程之间的调用。