[英]Getting ALL Email headers with Microsoft Graph SDK in a unified list?
我正在使用 Microsoft Graph 從特定帳戶的收件箱中獲取信息。 該帳戶有多個 email 別名。 但是,即使在我$select
查詢InternetMessageHeaders
屬性之后,它也不包括 email 發送到的別名。
我發現如果我也 select 並使用singleValueExtendedProperties
擴展查詢,我得到了我需要的東西,但現在我缺少InternetMessageHeaders
中存在的一些標題。 它還以一個巨大的文本塊返回,似乎不太直接解析。 如果我能以某種方式將此文本塊解析為鍵:值 map,我可以合並這兩個值並收工,但我不知道這是否可能。 我希望multiValueExtendedProperties
可以實現,但我認為這不是它的預期用途。
我正在為 .NET 使用 Microsoft Graph 的 SDK(目前使用 4.0.0),這就是我迄今為止收到的所有電子郵件:
public async Task<List<Message>> PollEmails() {
var completeList = new List<Message>();
var messagesRequest = await graphClient.
Users[GraphOptions.AccountId] // Email account ID
.Messages // All Emails
.Request() // Create request w/ authorization & headers needed
.Select("internetMessageHeaders,singleValueExtendedProperties") // Additionally, select the email's headers
.Expand("singleValueExtendedProperties($filter=id eq 'String 0x007D')") // Without this filter, we cannot tell which email alias was used in the To: field
.Top(100) // Get emails in batches of 100 (default is 10)
.GetAsync(); // Run request and await results
completeList.AddRange(messagesRequest);
// Results are paginated, so keep getting all the results until there are no more pages
while (messagesRequest.NextPageRequest != null) {
messagesRequest = await messagesRequest.NextPageRequest.GetAsync();
completeList.AddRange(messagesRequest);
}
return completeList;
}
Message.InternetMessageHeaders
具有我需要的大部分標頭,並且 rest 位於Message.SingleValueExtendedProperties
中,但是沒有簡單的方法可以將兩者合並到一個沒有重復標頭的列表中。
我可以盲目地將InternetMessageHeaders
和 append $"{Name}: {Value}"
循環到SingleValueExtendedProperties
值,但我最終會得到重復的標題。 我可以在 append 之前搜索密鑰的字符串,但這感覺就像一個黑客。
是否有使用 Microsoft Graph 的 SDK 獲取每個 header的官方方法?
謝謝,
編輯
這是一個比較標題的列表,以防有人好奇我對以"ARC-*"
開頭的標題的含義:
這是我從InternetMessageHeaders
以 JSON 格式返回的示例(來自 API): https://pastebin.com/Bdk35C5q
這是我從SingleValueExtendedProperties
以純文本形式返回的內容: https://pastebin.com/N7c0JLB6
不回答我的問題的相關問題:
Microsoft Graph:如何從 email 消息中獲取別名? - 如何通過singleValueExtendedProperties
獲取別名 email - 不包括以ARC-*
開頭的標頭
使用缺少一些 InternetMessageHeaders 的 Graph 獲取消息- 再次通過singleValueExtendedProperties
獲取“完整”標題列表 - 再次,不包括以ARC-*
開頭的標題
https://docs.microsoft.com/en-us/answers/questions/673767/how-to-read-all-internet-message-headers-of-an-ite.html - 問我到底在問什么從來沒有得到回應。
原來 Outlook 與每個 email 具有的標題不一致。 所以,在這種情況下, singleValueExtendedProperties
實際上是我需要的。
正如 Dmitry 指出的那樣,我沒有意識到我需要的是 MAPI 屬性(感謝您的澄清)。
如果其他人在我發現其他問題之前偶然發現了這個問題,那么您需要執行以下操作才能訪問 MAPI 屬性:
API:
GET https://graph.microsoft.com/v1.0/users/{id | userPrincipalName}/messages/{id}?$expand=singleValueExtendedProperties($filter id eq 'String 0x007D')
SDK:
// Since `$select` only returns the properties you specify and the only way to get this property is with both `$select` and `$expand`, you have to manually select all the properties you want. Thanks, Microsoft.
var selectProperties =
"id,subject,receivedDateTime,sentDateTime,from,toRecipients,ccRecipients,bccRecipients," +
"replyTo,internetMessageHeaders,singleValueExtendedProperties,bodyPreview,body,hasAttachments," +
"sender,categories,parentFolderId,conversationId,conversationIndex,isDeliveryReceiptRequested," +
"isReadReceiptRequested,isRead,isDraft,webLink,inferenceClassification,flag";
// Get user's emails (Requires permission Mail.Read) -
var messagesRequest = await graphClient.
Users[AccountId] // Replace this with account ID
.Messages // All Emails (or specify specific email via ["emailId"]
.Request() // Create request w/ authorization & headers needed
.Select(selectProperties) // Select all the specified properties
.Expand("singleValueExtendedProperties($filter=id eq 'String 0x007D')") // Select MAPI property Transport Message Headers to get the original `To:` email
.Top(100) // Get emails in batches of 100 (default is 10)
.GetAsync();
有關 MAPI 屬性的完整列表,請參閱此頁面。 有關此示例中使用的特定 MAPI 屬性,請參閱此頁面。
你能從.Net Microsoft Graph API 得到 PR_TRANSPORT_MESSAGE_HEADERS 0x007D 嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.