[英]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.