使用 PowerShell 从 Outlook 中读取最近的电子邮件 [英] Read most recent e-mail from outlook using PowerShell

查看:168
本文介绍了使用 PowerShell 从 Outlook 中读取最近的电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试阅读主题为自动化"的 Outlook 电子邮件,并使用自定义脚本进一步处理.下面的脚本读取主题行的电子邮件,但读取主题为自动化"的电子邮件的全部计数.

I am trying to read my Outlook e-mail with the subject line "Automation" and process further with custom script. The below script reads the e-mail with the subject line but it reads the entire count of e-mail with the subject "Automation".

我希望能够仅阅读最近的电子邮件并仅处理该特定电子邮件内容并将电子邮件标记为未读.然后阅读下一封相同主题的新邮件,只处理具体内容.

I want to be able to read only the most recent e-mail and process only that specific e-mail content and mark the e-mail as unread. And then read the next new e-mail with the same subject and process only the specific content.

Add-type -assembly "Microsoft.Office.Interop.Outlook" | out-null
$olFolders = "Microsoft.Office.Interop.Outlook.olDefaultFolders" -as [type]
$outlook = new-object -comobject outlook.application
$namespace = $outlook.GetNameSpace("MAPI")
$folder = $namespace.getDefaultFolder($olFolders::olFolderInBox)
$folder.items | where { $_.subject -match 'Automation' } | Select-Object -Property body

假设我有 10 封主题为自动化"的新电子邮件处理第 10 封电子邮件并标记为已读并继续从 9 到 1 处理.

Let's say if I have 10 new e-mail with subject "Automation" process 10th e-mail and mark as read and continue to process from 9 to 1.

如何实现这一目标?

推荐答案

刚好使用了一个foreach-object,你可以通过修改邮件的未读属性来将邮件标记为已读/未读项目 ( https://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook._mailitem.unread.aspx )

Just got to use a foreach-object, you can mark the mail as read/unread by modifying the unread property of a mail item ( https://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook._mailitem.unread.aspx )

$outlook = new-object -comobject outlook.application
$namespace = $outlook.GetNameSpace("MAPI")
$folder=$namespace.GetDefaultFolder(6)
$folder.Items | 
    ?{$_.subject -match "automation" } |
    sort receivedtime -desc | 
    %{
         echo $_.body #do stuff with body 
         $_.Unread=$false #mark as read        
     }

发表评论后,您可以验证您的 Outlook 版本是否公开了未读属性:$folder.Items |select -first 1 |获取会员您应该找到以下属性:
UnRead 属性 bool UnRead() {get} {set}

After your comment you can verify if your outlook version expose the unread property with : $folder.Items |select -first 1 | get-member you should find the following property :
UnRead Property bool UnRead () {get} {set}

这篇关于使用 PowerShell 从 Outlook 中读取最近的电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆