前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >PowerShell监控outlook新邮件到达PowerShell监控outlook新邮件到达

PowerShell监控outlook新邮件到达PowerShell监控outlook新邮件到达

作者头像
xiny120
发布2021-12-06 17:41:24
6740
发布2021-12-06 17:41:24
举报
文章被收录于专栏:毛毛v5

PowerShell监控outlook新邮件到达(单封,多封可能要分解id(旧版需分解?新版不需要?新版就是每个邮件出发一次newmailex?看如下documents))

代码语言:javascript
复制
This event fires once for every received item that is processed by Microsoft Outlook.
The item can be one of several different item types, 
for example, **[MailItem](https://docs.microsoft.com/en-us/office/vba/api/outlook.mailitem)**, **[MeetingItem](https://docs.microsoft.com/en-us/office/vba/api/outlook.meetingitem)**, or **[SharingItem](https://docs.microsoft.com/en-us/office/vba/api/outlook.sharingitem)**. 
The *EntryIDsCollection* string contains the Entry ID that corresponds to that item. 
Note that this behavior has changed from earlier versions of the event when the *EntryIDCollection* contained a list of comma-delimited Entry IDs of all the items received in the Inbox since the last time the event was fired.
代码语言:javascript
复制
Add-Type -assembly "Microsoft.Office.Interop.Outlook"
add-type -assembly "System.Runtime.Interopservices"

try{
    $outlook = [Runtime.Interopservices.Marshal]::GetActiveObject('Outlook.Application')
    $outlookWasAlreadyRunning = $true
}catch{
    try{
        $Outlook = New-Object -comobject Outlook.Application
        $outlookWasAlreadyRunning = $true
    }catch{
        write-host "You must exit Outlook first."
        exit
    }
}

$test ='abc'
$vars = Get-Variable

#Write-Host ($vars | Format-List | Out-String)

try{
    if($outlookWasAlreadyRunning){
        write-host "ok..."

        $Job = Register-ObjectEvent -InputObject $Outlook -EventName NewMailEx `
        -Action {
            #($Event,$EventSubscriber,$Sender,$SourceEventArgs,$SourceArgs)
            #$Event, $EventSubscriber, $Sender, $EventArgs, and $Args
            #$EventArgs | Format-List -Property *
            #$Args | Format-List -Property *
            #-Sender $sender
            #$test ='abc'
            #write-host "testaaa123.."
            #write-host ""
            #$outline = Get-Event
            #$vars = Get-Variable
            #write-host '$(outline)'
            #Write-Host ($Args | Format-List | Out-String)
            #Write-Host ($args | Format-List | Out-String)
            #Write-Host ($vars | Format-List | Out-String)
            #$sender | Format-List -Property *
            #Write-Host ($args | Format-List)

            $mail = $Outlook.Session.GetItemFromID($args)
            #Write-Host ($mail | Format-List | Out-String)
            Write-Host $mail.Subject
            Write-Host $mail.Body
            write-host ""
        }

        #$Job | Format-List -Property *

        while($true){
        }
    }
}finally{
   Unregister-Event -SubscriptionId $Job.Id
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2021/8/26 上,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档