您有需要准备Outlook电子邮件草稿并在Outlook中打开它。无法在Outlook应用程序上使用PowerShell创建Outlook电子邮件草稿
我已经创建了php窗体来运行供应变量到powershell,这将调用outlook方法并创建电子邮件。
当我执行PowerShell的如下
C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe C:\wamp\www\bizops\prepare_email.ps1 >> C:\wamp\www\bizops\log.log
它完美。
但是,当我把上面的线在批处理文件并调用它在PHP脚本,
$mail_string="c:\WINDOWS\system32\cmd.exe /c START C:\wamp\www\bizops\outlook_mail.bat";
exec($mail_string);
它给了我下面的错误
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)).At C:\wamp\www\bizops\prepare_email.ps1:25 char:7
+ $ol = New-Object -comObject Outlook.Application
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (:) [New-Object], COMException
+ FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand
我PowerShell代码看起来像(节这thorows这个错误)
$ol = New-Object -comObject Outlook.Application
$ns = $ol.GetNameSpace("MAPI")
$Mail = $ol.CreateItem(0)
$Mail.Recipients.Add($mail_to_list)
$mail.Subject = $mail_subject
$mail.DeferredDeliveryTime = $deliverAt
$Mail.HTMLBody = "SOME HTML TEXT"
嗨德米特里, 是否有任何检查两个进程是否在不同的安全上下文中运行? 你能提出解决方法吗? 谢谢 – Vijay
捕获异常并处理这个特定的COM代码(0x80080005)可能是最好的方法。 –