如何摆脱操作确认窗口?

时间:2016-02-24 09:21:47

标签: powershell outlook

PowerShell 4.0,MS Outlook 2003 SP3

我通过以下功能通过Outlook发送消息:

# Code sources:
# http://www.computerperformance.co.uk/powershell/powershell_function_send_email.htm
Function Global:Send-Email {
[cmdletbinding()]
Param (
[Parameter(Mandatory=$False,Position=0)]
[String]$Address = "abcd@yandex.ru",
[Parameter(Mandatory=$False,Position=1)]
[String]$Subject = "Hello!",
[Parameter(Mandatory=$False,Position=2)]
[String]$Body = "Hello from PowerShell through Outlook."
      )
Begin {
Clear-Host
# Add-Type -assembly "Microsoft.Office.Interop.Outlook"
    }
Process {
# Create an instance Microsoft Outlook
$Outlook = New-Object -ComObject Outlook.Application
$Mail = $Outlook.CreateItem(0)
$Mail.To = "$Address"
$Mail.Subject = $Subject
# $Mail.Body =$Body
$Mail.HTMLBody = "<b>When</b> is swimming?"
$File = "$env:HOMEDRIVE\Temp\1.txt"
$Mail.Attachments.Add($File)
$Mail.Send()
       } # End of Process section
End {
# Section to prevent error message in Outlook
$Outlook.Quit()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($Outlook)
$Outlook = $null
   } # End of End section!
} # End of function

# Example of using this function
Send-Email #-Address deck@swimmingpool.com

当我使用它时,Outlook会向我显示窗口:

enter image description here

这是操作确认的请求。如何摆脱这个窗口?

2 个答案:

答案 0 :(得分:0)

如果需要,可以在Outlook Trustcenter(选项 - 信任中心 - 程序访问)中禁用此警告。

答案 1 :(得分:0)

您需要使用扩展MAPI(仅限C ++或Delphi)或类似Redemption的包装器来避免安全提示。有关详细信息,请参阅http://www.outlookcode.com/article.aspx?id=52