无法使用IIS Windows Server 2012将使用php脚本的Powershell电子邮件发送到Outlook [英] Unable to send powershell email using php script to outlook using iis windows server 2012
问题描述
错误-:
New-Object:检索具有CLSID的组件的COM类工厂 {0006F03A-0000-0000-C000-000000000046}由于以下原因而失败 错误:80010001被呼叫者拒绝了呼叫. (来自HRESULT的异常: 0x80010001(RPC_E_CALL_REJECTED)).在D:\ get-process.ps1:5 char:12 + $ Outlook =新对象-ComObject Outlook.Application + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + CategoryInfo: 资源不可用:(:) [New-Object],COMException + FullyQualifiedErrorId: NoCOMClassIdentified,Microsoft.PowerShell.Comman ds.NewObjectCommand 您不能在空值表达式上调用方法.在 D:\ get-process.ps1:6 char:1 + $ Mail = $ Outlook.CreateItem(0)+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + CategoryInfo:InvalidOperation:(:) [],RuntimeException + FullyQualifiedErrorId:InvokeMethodOnNull 在此对象上找不到属性"To".验证属性 存在并且可以设置.在D:\ get-process.ps1:8 char:1 + $ Mail.To = "$ username" + ~~~~~~~~~~~~~~~~~~~~~ + + CategoryInfo: InvalidOperation:(:) [],RuntimeException + FullyQualifiedErrorId: PropertyNotFound在此找不到属性主题" 目的.验证该属性存在并且可以设置.在 D:\ get-process.ps1:9 char:1 + $ Mail.Subject =新请假请求" + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo:InvalidOperation: (:) [],RuntimeException + FullyQualifiedErrorId:PropertyNotFound 在此对象上找不到属性身体".验证 属性存在并且可以设置.在D:\ get-process.ps1:10 char:1 + $ Mail.Body ="$ username" + ~~~~~~~~~~~~~~~~~~~~~~~ + + CategoryInfo: InvalidOperation:(:) [],RuntimeException + FullyQualifiedErrorId: PropertyNotFound您不能在空值表达式上调用方法. 在D:\ get-process.ps1:12 char:1 + $ Mail.Send()+ ~~~~~~~~~~~~ + CategoryInfo:InvalidOperation:(:) [],RuntimeException + FullyQualifiedErrorId:InvokeMethodOnNull你好 devang_gaur@outlook.com
New-Object : Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80010001 Call was rejected by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED)). At D:\get-process.ps1:5 char:12 + $Outlook = New-Object -ComObject Outlook.Application + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ResourceUnavailable: (:) [New-Object], COMExcept ion + FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Comman ds.NewObjectCommand You cannot call a method on a null-valued expression. At D:\get-process.ps1:6 char:1 + $Mail = $Outlook.CreateItem(0) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull The property 'To' cannot be found on this object. Verify that the property exists and can be set. At D:\get-process.ps1:8 char:1 + $Mail.To = "$username" + ~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : PropertyNotFound The property 'Subject' cannot be found on this object. Verify that the property exists and can be set. At D:\get-process.ps1:9 char:1 + $Mail.Subject = "New Leave Request" + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : PropertyNotFound The property 'Body' cannot be found on this object. Verify that the property exists and can be set. At D:\get-process.ps1:10 char:1 + $Mail.Body = "$username" + ~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : PropertyNotFound You cannot call a method on a null-valued expression. At D:\get-process.ps1:12 char:1 + $Mail.Send() + ~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull Hello devang_gaur@outlook.com
get-process.php-:
<?php
$username = "devang_gaur@outlook.com";
$psScriptPath = "D:\\get-process.ps1";
$query = shell_exec("powershell -command $psScriptPath -username '$username'< NUL");
echo $query;
?>
get-process.ps1-:
param(
[string]$username
)
$Outlook = New-Object -ComObject Outlook.Application
$Mail = $Outlook.CreateItem(0)
$Mail.To = "$username"
$Mail.Subject = "New Leave Request"
$Mail.Body = "$username"
$Mail.Send()
Write-Output "Hello $username <br />"
get-process.php
是IIS Windows Server 2012的根文件夹wwwroot
中存在的php,从中触发PowerShell脚本get-process.ps1
. Get-process.ps1
包含用于发送邮件的脚本
get-process.php
is the php that is present in root folder wwwroot
of IIS Windows Server 2012 and from which the PowerShell script get-process.ps1
is triggered. Get-process.ps1
contains script for sending the mail
推荐答案
Microsoft当前不建议也不支持任何无人参与的非交互客户端应用程序或组件(包括ASP,ASP)中的Microsoft Office应用程序自动化. NET,DCOM和NT服务),因为在这种环境下运行Office时,Office可能表现出不稳定的行为和/或死锁.
Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
如果要构建在服务器端上下文中运行的解决方案,则应尝试使用对无人值守执行安全的组件.或者,您应该尝试找到允许至少部分代码在客户端运行的替代方法.如果您使用服务器端解决方案中的Office应用程序,则该应用程序将缺少许多成功运行所需的功能.此外,您将承担整体解决方案稳定性的风险.在服务器端Office自动化注意事项一文中了解有关此内容的更多信息.
If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution. Read more about that in the Considerations for server-side Automation of Office article.
相反,您可以考虑使用基于Outlook的低级API-扩展MAPI.或该API的任何其他包装,例如Redemption.
Instead, you may consider using a low-level API on which Outlook is based on - Extended MAPI. Or any other wrapper around that API, for example, Redemption.
这篇关于无法使用IIS Windows Server 2012将使用php脚本的Powershell电子邮件发送到Outlook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!