根据标题,这些字段为空。 Outlook 中的同一邮件肯定不会缺少这些标头。
Add-Type -AssemblyName "Microsoft.Office.Interop.Outlook" -ErrorAction Stop
$OutlookApp = New-Object -ComObject "Outlook.Application"
$OutlookNS = $OutlookApp.GetNamespace("MAPI")
$OutlookNS.Logon()
$RootFolder = $OutlookNS.Folders() | Where-Object { $_.FullFolderPath -eq "\\[email protected]" }
$TargetFolder = $RootFolder.Folders() | Where-Object { $_.Name -eq "Inbox" }
$StartDate = (Get-Date).AddDays(-1)
$EndDate = (Get-Date)
$filter = "@SQL=""urn:schemas:httpmail:datereceived"">='$($StartDate.ToString("MM/dd/yyyy HH:MM:ss"))' And ""urn:schemas:httpmail:datereceived""<='$($EndDate.ToString("MM/dd/yyyy HH:MM:ss"))'"
$MailItems = $TargetFolder.Items.Restrict($filter) | Where-Object { $_ -is [Microsoft.Office.Interop.Outlook.MailItem] }
$MailItems.Item(1) | Select-Object SenderEmailAddress, "To", Subject, SenderName, ReceivedTime, LastModificationTime
MailItem
对象不会公开名为 From
的属性。使用 SenderName
/ SenderEmailAddress
/等。有关更多详细信息,请参阅 https://learn.microsoft.com/en-us/office/vba/api/outlook.mailitem。
您可能还想使用
Namespace.GetDefaultFolder
/ Store.GetDefaultFolder
检索收件箱文件夹 (olFolderInbox
),而不是按名称检索它。