【问题标题】:Outlook Items.Restrict Does not return all messagesOutlook Items.Restrict 不返回所有邮件
【发布时间】:2011-10-11 15:59:22
【问题描述】:

我有一个小型 powershell 脚本,它使用 Outlook 互操作将某些邮件从收件箱移动到其他文件夹。基本的移动操作使用以下代码完成:

[Reflection.Assembly]::LoadWithPartialname("Microsoft.Office.Interop.Outlook") | Out-Null
$olFolders = "Microsoft.Office.Interop.Outlook.OlDefaultFolders" -as [type] 
$outlook = new-object -comobject outlook.application
$namespace = $outlook.GetNameSpace("MAPI")
$inbox = $namespace.getDefaultFolder($olFolders::olFolderInbox)
$filter = "[SenderName] = 'Dummy Sender'"
$messages = $inbox.items.Restrict($filter)
$messages | % { 
    Write-Host "`t$($_.Subject)" 
    [void]$_.Move($destination) | Out-Null
}

我注意到的问题是items.Restrict 没有返回所有匹配的消息。每次运行脚本时,我都会收到 3 到 20 条消息。

以前有人观察过这种行为吗?我有什么明显的遗漏吗?

【问题讨论】:

  • 我已经完成了各种 SenderName 和 $message.count 匹配 Outlook 上的计数(也与来自发件人的 567 封邮件)

标签: powershell outlook office-interop outlook-2007 mapi


【解决方案1】:

当您仍在循环中时,您正在修改集合。 要么将条目 ID 保存到静态数组/列表中,然后一次重新打开一条消息,要么使用从倒计时到 1 的循环。

【讨论】:

  • doh...感谢您的注意和指出。我会站在我房间的一个角落里。 :-(
猜你喜欢
  • 2015-10-27
  • 2016-10-16
  • 1970-01-01
  • 2016-06-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-31
  • 1970-01-01
相关资源
最近更新 更多