2

我见过几种使用 PowerShell 自动化本地 Outlook 客户端的解决方案,但我希望它在服务器端运行:使用给定帐户访问服务器,检查未读邮件,将所有附件保存到文件共享并标记消息已读。

4

2 回答 2

1

这需要安装Exchange 托管服务 API

$ewsPath = "C:\Program Files\Microsoft\Exchange\Web Services\2.2\Microsoft.Exchange.WebServices.dll"
Add-Type -Path $ewsPath

$ews = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService
$cred = (Get-Credential).GetNetworkCredential()
$ews.Credentials = New-Object System.Net.NetworkCredential -ArgumentList $cred.UserName, $cred.Password, $cred.Domain
$ews.AutodiscoverUrl( "user@domain.com", {$true} )
$results = $ews.FindItems(
    "Inbox",
    ( New-Object Microsoft.Exchange.WebServices.Data.ItemView -ArgumentList 100 )
)
$MailItems = $results.Items | where hasattachments

foreach ($MailItem in $MailItems){

    $MailItem.Load()

    foreach($Attachment in $MailItem.Attachments){
        $Attachment.Load()
        $File = new-object System.IO.FileStream(("C:\Temp\” + $attachment.Name.ToString()), [System.IO.FileMode]::Create)
        $File.Write($attachment.Content, 0, $attachment.Content.Length)
        $File.Close()
    }
}
于 2016-05-06T19:14:34.120 回答
0

您在 Exchange 环境中吗?如果是这样,并且 Exchange Web 服务暴露给网络,这是一个选项。

于 2016-05-04T21:19:08.887 回答