1
以下PowerShell腳本已適應我們的情況。 它讀取收件箱文件夾中的所有電子郵件,然後提取附件如何使用EWS將項目移動到文件夾?
它運行良好,但我想將項目移動到「/ Processed」郵箱根文件夾。此文件夾不是收件箱文件夾的子文件夾:
Mailbox
L Inbox
L Processed
L Sent Items
L Deleted Items
如果我使用下面的行
[VOID]$miMailItems.Move("DeletedItems")
然而,由於預期這是行不通的。它刪除了電子郵件,但在我的個人郵箱中,不是「john」郵箱!
所以,使用的代碼時,你能幫助我
- 更正代碼移動項目到約翰郵箱
[VOID]$miMailItems.Move("DeletedItems")
- 讓我知道我可以簡單地移動物品的約翰「已處理」郵箱子文件夾?
$MailboxName = '[email protected]'
$downloadDirectory = '\\share\'
$dllpath = "C:\Program Files\Microsoft\Exchange Server\V15\Bin\Microsoft.Exchange.WebServices.dll"
[VOID][Reflection.Assembly]::LoadFile($dllpath)
$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2013)
$sidbind = "LDAP://<SID=" + (Get-ADUser exchadmin).SID.ToString() + ">"
$aceuser = [ADSI]$sidbind
$service.AutodiscoverUrl($aceuser.mail.ToString())
$folderid = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$MailboxName)
$InboxFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderid)
$Sfha = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo([Microsoft.Exchange.WebServices.Data.EmailMessageSchema]::HasAttachments, $true)
$sfCollection = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+SearchFilterCollection([Microsoft.Exchange.WebServices.Data.LogicalOperator]::And);
$sfCollection.add($Sfha)
$view = new-object Microsoft.Exchange.WebServices.Data.ItemView(2000)
$frFolderResult = $InboxFolder.FindItems($sfCollection,$view)
foreach ($miMailItems in $frFolderResult.Items){
$miMailItems.Load()
foreach($attach in $miMailItems.Attachments){
$attach.Load()
$fiFile = new-object System.IO.FileStream(($downloadDirectory + 「\」 + (Get-Date).Millisecond + "_" + $attach.Name.ToString()), [System.IO.FileMode]::Create)
$fiFile.Write($attach.Content, 0, $attach.Content.Length)
$fiFile.Close()
}
$miMailItems.isread = $true
$miMailItems.Update([Microsoft.Exchange.WebServices.Data.ConflictResolutionMode]::AlwaysOverwrite)
# The following send items to my personal "Deleted Items" folder instead of the john mailbox...
[VOID]$miMailItems.Move("DeletedItems")
# How can I send items to the "/Processed" folder of the john mailbox ?
}