本文介绍了Exchange 2010-在邮件接收上运行命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道有没有一种方法可以使Exchange Server 2010在收到某些邮箱的邮件后执行某些程序?

Does anyone know is there a way to make Exchange server 2010 execute some program upon mail receive for some mailbox ?

例如:

我有邮件[email protected][email protected]

I have mails [email protected] and [email protected]

我想在邮件到达[email protected]时执行program1.exe并在邮件到达[email protected]时执行program2.exe

I want to execute program1.exe when mail arrives to [email protected] execute program2.exe when mail arrives to [email protected]

我已经查看了Exchange管理控制台中的所有选项,但没有发现任何类似的东西.

I have looked all options in Exchange management console, and didn't find anything similar.

推荐答案

我使用EWS和powershell做过类似的事情.您可以下载EWS此处

I made something similar using EWS and powershell. You can download EWShere

然后,您可以在Powershell中创建使用Exchange Web服务的脚本

Then you can create an script in powershell that use the Exchange web service

这是我的脚本示例:

$MailboxName = "[email protected]"
$dllpath = "C:\Program Files\Microsoft\Exchange\Web Services\2.0\Microsoft.Exchange.WebServices.dll"
[void][Reflection.Assembly]::LoadFile($dllpath)
$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP1)
$service.TraceEnabled = $false

$service.Credentials = New-Object System.Net.NetworkCredential("name","password", "domain")
$service.Url="https://mail.yourdomain.com.au/ews/exchange.asmx"

try{
$fldArray = new-object Microsoft.Exchange.WebServices.Data.FolderId[] 1
$Inboxid = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$MailboxName)
$fldArray[0] = $Inboxid
$stmsubscription = $service.SubscribeToStreamingNotifications($fldArray, [Microsoft.Exchange.WebServices.Data.EventType]::NewMail)
$stmConnection = new-object Microsoft.Exchange.WebServices.Data.StreamingSubscriptionConnection($service, 30);
$stmConnection.AddSubscription($stmsubscription)
Register-ObjectEvent -inputObject $stmConnection -eventName "OnNotificationEvent" -Action {

    foreach($notEvent in $event.SourceEventArgs.Events){
        [String]$itmId = $notEvent.ItemId.UniqueId.ToString()
        $message = [Microsoft.Exchange.WebServices.Data.EmailMessage]::Bind($event.MessageData,$itmId)
        IF ($message.Subject -eq "execprocess"){
            Start-Process  "mybat.bat"
        }
    }


} -MessageData $service

}catch [Exception] {
                Get-Date  | Out-File C:\logs\logError.txt -Append
                "Error : "+  $_.Exception.Message
                }
Register-ObjectEvent -inputObject $stmConnection -eventName "OnDisconnect" -Action {$event.MessageData.Open()} -MessageData $stmConnection
$stmConnection.Open()

然后,为您需要监视的每个帐户运行2个脚本.

Then, run the 2 scripts one for every account you need to monitoring.

在此处查看原始示例-> 来源

See the original example here--> Source

这篇关于Exchange 2010-在邮件接收上运行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 19:11