PowerShell EWS SendAndSaveCopy()在特定文件夹中

时间:2015-06-02 08:45:50

标签: powershell exchangewebservices

我正在试图找出EWS的正确语法,以便能够存储在特定文件夹中发送的邮件,而不仅仅是在“已发送邮件”文件夹中。

邮箱结构:

Mailbox@mail.com
- Inbox
- ----- PowerShell
- ----- ---------- Mail OUT

如何让EWS在Inbox\PowerShell\Mail OUT中保存已发送的邮件?

我尝试了以下但没有成功:

$Message.SendAndSaveCopy('WellKnownFolderName.Inbox.PowerShell.Mail OUT')
$Message.SendAndSaveCopy('WellKnownFolderName.Inbox\PowerShell\Mail OUT')
$Message.Send()
$Message.Save([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::'Inbox\PowerShell\Mail OUT')

MSDN上的示例仅对C#有效。

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

首先,正如arco444指出的那样,我们需要检索FolderId号码。之后,simle SendSave就可以了。

对任何有兴趣的人:

Function Find-FolderID {
    Param (
        [Parameter(Mandatory)]
        [String]$Path,
        [Parameter(Mandatory)]
        [String]$Mailbox,
        [Parameter(Mandatory)]
        [Object]$Service
    )

    $FolderId = New-Object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::MsgFolderRoot,$Mailbox)
    $TargetFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($Service,$FolderId)  

    $Array = $Path.Split('\')

    for ($i=1; $i -lt $Array.Length; $i++) {
            $FolderView = New-Object Microsoft.Exchange.WebServices.Data.FolderView(1) 
            $SearchFilter = New-Object Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo([Microsoft.Exchange.WebServices.Data.FolderSchema]::DisplayName,$Array[$i]) 
            $Results = $service.FindFolders($TargetFolder.Id,$SearchFilter,$FolderView) 
            if ($Results.TotalCount -gt 0) { 
                foreach($R in $Results.Folders) { 
                    $TargetFolder = $R                
                } 
            } 
            else { 
                throw "Folder '$Path' not found in mailbox '$Mailbox'"
            }     
    }  
    $TargetFolder.Id
}

Find-FolderId -Path '\Inbox\PowerShell\Expiring users OUT' -Mailbox 'Mailbox@mail.com' -Service $EWS

$Message.Send()
$Message.Save($FolderID)