使用Outlook COM获取邮件时SenderEmailAddress等字段为空问题
Outlook Interop 获取邮件部分字段为空问题
正如标题所述,通过PowerShell调用Outlook Interop获取邮件时,部分字段返回空值,但在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 "\\foo@bar.com" } $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
以下是某封邮件的属性检测情况:属性本身存在,但部分属性的数据为空(或对应的COM对象为空):
| 有数据 | 无数据 |
|---|---|
| Actions | AutoForwarded |
| AlternateRecipientAllowed | AutoResolvedWinner |
| Application | BCC |
| BodyFormat | BillingInformation |
| Class | Body |
| ConversationID | Categories |
| ConversationIndex | CC |
| ConversationTopic | Companies |
| CreationTime | DeleteAfterSubmit |
| DeferredDeliveryTime | FlagIcon |
| DownloadState | FlagRequest |
| EnableSharedAttachments | FlagStatus |
| EntryID | HasCoverSheet |
| ExpiryTime | HTMLBody |
| FlagDueBy | IsConflict |
| FormDescription | IsIPFax |
| GetInspector | IsMarkedAsTask |
| Importance | Links |
| InternetCodepage | MarkForDownload |
| ItemProperties | Mileage |
| LastModificationTime | NoAging |
| MAPIOBJECT | OriginatorDeliveryReportRequested |
| MessageClass | OutlookInternalVersion |
| Parent | OutlookVersion |
| ReceivedByEntryID | Permission |
| ReceivedOnBehalfOfEntryID | PermissionService |
| ReceivedTime | PermissionTemplateGuid |
| ReminderTime | PropertyAccessor |
| RetentionExpirationDate | ReadReceiptRequested |
| Saved | ReceivedByName |
| SaveSentMessageFolder | ReceivedOnBehalfOfName |
| SenderEmailType | RecipientReassignmentProhibited |
| SendUsingAccount | Recipients |
| Sent | ReminderOverrideDefault |
| SentOn | ReminderPlaySound |
| Session | ReminderSet |
| Size | ReminderSoundFile |
| Subject | RemoteStatus |
| TaskCompletedDate | ReplyRecipientNames |
| TaskDueDate | ReplyRecipients |
| TaskStartDate | RetentionPolicyName |
| TaskSubject | RTFBody |
| ToDoTaskOrdinal | Sender |
| UnRead | SenderEmailAddress |
| SenderName | |
| Sensitivity | |
| SentOnBehalfOfName | |
| Submitted | |
| To | |
| VotingOptions | |
| VotingResponse |
内容的提问来源于stack exchange,提问作者Tyler
相关产品推荐
相关产品推荐

