【发布时间】:2021-05-22 14:35:37
【问题描述】:
我正在尝试自动回复我在 Outlook 中收到的一些电子邮件。我尝试使用 powershell 从我的 Outlook(普通邮件)发送邮件,并且成功。现在我正在尝试使用 powershell 回复邮件。这是我目前的代码:
$o = New-Object -com Outlook.Application
$all_mail = $o.Session.Folders.Item($myEmailId).Folders.Item("Inbox").Items
foreach ($mail in $all_mail) {
if ($mail.subject -match "Re: Testing") {
$reply = $mail.reply()
$reply.body = $reply.body + "Adding this extra info in mail."
$reply.send()
}
}
#myEmailId is my emailId, if trying this script, replace it with yours.
当我运行它时,我收到以下错误
Operation aborted (Exception from HRESULT: 0x80004004 (E_ABORT))
At line:7 char:13
+ $reply.send()
+ ~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
我在调试期间打印了日志,发现它成功地接收了我的 Outlook 中的所有电子邮件。与邮件主题匹配的 if 条件也可以正常工作。我尝试浏览互联网上的各种资源,但找不到任何解决方案。任何帮助或指导都会非常有帮助。
【问题讨论】:
-
很高兴看到您发现了一个选项,但是,我真的不清楚您的用例在这里。对于您的用例,您已经必须打开 Outlook 以了解/获取主题名称以响应、关闭 Outlook 并运行您的自动化。您在 Outlook 中,只需使用 VBA 旋转宏来响应电子邮件线程。没有打开/关闭 Outlook,启动 PowerShell 以执行您在打开时可以执行的操作。所以,叫我好奇。并不是说这个评论真的需要回应,因为你有自己的答案,但是,你知道的。 ;-},顺便说一句,您可以从 Outlook VBA 运行 PS 脚本。
标签: powershell email outlook automation reply