如何从共享Outlook邮箱访问电子邮件

时间:2019-06-10 02:55:45

标签: powershell outlook shared

我需要从共享Outlook邮箱中获取最新电子邮件。

共享收件箱例如。找到“服务器备份”和我要获取的电子邮件 收件箱\备份报告\ 这是一些我可以访问我的收件箱但不能用于子文件夹的代码

$Outlook = New-Object -ComObject Outlook.Application
$OutlookFolders = $Outlook.Session.Folders.Item(1).Folders
$OutlookInbox = $Outlook.session.GetDefaultFolder(6)
#read the latest email
$latestmail=$OutlookInbox.items | select -last 1

2 个答案:

答案 0 :(得分:0)

您追求的是进一步向下导航。

$outlook = New-Object -Com Outlook.Application
$MAPI = $Outlook.GetNamespace("MAPI")

# Gets all mailboxes tied to the account
$Mailbox = $MAPI.Folders("SharedEmail@Company.com")

# Gets the Inbox folder
$Inbox = $mailbox.Folders("Inbox").Folders("backup report")

# Shows all emails from the Inbox
$contents = $Inbox.Items
$contents.Sort("ReceivedTime", $true)
$contents | select Subject, SenderName, CreationTime -First 1

编辑:由于以上操作无效,请尝试以下操作。它将搜索“收件箱”,然后通过管道搜索“服务器备份”。

$Outlook = New-Object -ComObject Outlook.Application
$OutlookFolders = $Outlook.Session.Folders.Item(1).Folders
(($OutlookFolders | Where-Object {$_.FolderPath -like "*Inbox*"}).Folders | `
    Where-Object {$_.FolderPath -like "*Server Backup*"}).Items | `
    select Subject, SenderName -Last 1

答案 1 :(得分:0)

$outlook = New-Object -comobject outlook.application
$namespace = $outlook.application.GetNamespace("MAPI")
$folder = $namespace.GetDefaultFolder(6)
#goto the inbox\backup eport and select the latest email and place it in variable 
#$newreport
$newreport = $namespace.Folders.Item("Server 
Backup").Folders.Item('Inbox').Folders.item('backups').items | select -first 1