Unable to send powershell email using php script to outlook using iis windows server 2012

廉价感情. 提交于 2019-12-25 05:36:52

问题


Error -:

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 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


回答1:


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.

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.

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.



来源:https://stackoverflow.com/questions/31668968/unable-to-send-powershell-email-using-php-script-to-outlook-using-iis-windows-se

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!