[英]Getting ALL Email headers with Microsoft Graph SDK in a unified list?
I'm using Microsoft Graph to get information from a specific account's inbox.我正在使用 Microsoft Graph 从特定帐户的收件箱中获取信息。 That account has multiple email aliases.
该帐户有多个 email 别名。 However, even after I
$select
query the InternetMessageHeaders
property, it does not include the alias the email was sent to.但是,即使在我
$select
查询InternetMessageHeaders
属性之后,它也不包括 email 发送到的别名。
I found out that if I also select and expand the query using singleValueExtendedProperties
, I get what I need, but now I'm missing some headers that are present in InternetMessageHeaders
.我发现如果我也 select 并使用
singleValueExtendedProperties
扩展查询,我得到了我需要的东西,但现在我缺少InternetMessageHeaders
中存在的一些标题。 It also comes back in a giant blob of text that doesn't seem too straight forward to parse.它还以一个巨大的文本块返回,似乎不太直接解析。 If I could somehow parse this blob of text into a key:value map, I could just merge both these values and call it a day, but I don't know if that's possible.
如果我能以某种方式将此文本块解析为键:值 map,我可以合并这两个值并收工,但我不知道这是否可能。 I was hoping it might be possible with
multiValueExtendedProperties
, but I don't think that's an intended use for it.我希望
multiValueExtendedProperties
可以实现,但我认为这不是它的预期用途。
I'm using Microsoft Graph's SDK for .NET (currently using 4.0.0) and this is what I have so far to get all the emails:我正在为 .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
has most of the headers I need, and the rest are in Message.SingleValueExtendedProperties
, but there's no easy way to merge the two into one list without duplicate headers. Message.InternetMessageHeaders
具有我需要的大部分标头,并且 rest 位于Message.SingleValueExtendedProperties
中,但是没有简单的方法可以将两者合并到一个没有重复标头的列表中。
I could just blindly loop through InternetMessageHeaders
and append $"{Name}: {Value}"
to the SingleValueExtendedProperties
value, but I'll end up with duplicate headers.我可以盲目地将
InternetMessageHeaders
和 append $"{Name}: {Value}"
循环到SingleValueExtendedProperties
值,但我最终会得到重复的标题。 I could just search the string for the key before I append it, but that just feels like a hack.我可以在 append 之前搜索密钥的字符串,但这感觉就像一个黑客。
Is there an official way to get every single header using Microsoft Graph's SDK?是否有使用 Microsoft Graph 的 SDK 获取每个 header的官方方法?
Thank you,谢谢,
EDIT编辑
Here's a list comparing the headers in case anyone is curious about what I meant with headers starting with "ARC-*"
:这是一个比较标题的列表,以防有人好奇我对以
"ARC-*"
开头的标题的含义:
This is an example (from the API) of what I get back from InternetMessageHeaders
in JSON format: https://pastebin.com/Bdk35C5q这是我从
InternetMessageHeaders
以 JSON 格式返回的示例(来自 API): https://pastebin.com/Bdk35C5q
This is what I get back from SingleValueExtendedProperties
in plain text: https://pastebin.com/N7c0JLB6这是我从
SingleValueExtendedProperties
以纯文本形式返回的内容: https://pastebin.com/N7c0JLB6
Related questions that don't answer my question:不回答我的问题的相关问题:
Microsoft Graph: How to get the alias from an email message? Microsoft Graph:如何从 email 消息中获取别名? - How to get the alias email used via
singleValueExtendedProperties
- doesn't include headers starting with ARC-*
- 如何通过
singleValueExtendedProperties
获取别名 email - 不包括以ARC-*
开头的标头
Get message using Graph missing some InternetMessageHeaders - Get "complete" list of headers, again via singleValueExtendedProperties
- again, doesn't include headers starting with 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 - Asking exactly what I'm asking but never got a response. https://docs.microsoft.com/en-us/answers/questions/673767/how-to-read-all-internet-message-headers-of-an-ite.html - 问我到底在问什么从来没有得到回应。
Turns out Outlook just isn't consistent with which headers each email has.原来 Outlook 与每个 email 具有的标题不一致。 So, in this case, the
singleValueExtendedProperties
was actually what I needed.所以,在这种情况下,
singleValueExtendedProperties
实际上是我需要的。
What I didn't realize I was asking for was I needed MAPI properties, as Dmitry pointed out (thank you for clarifying).正如 Dmitry 指出的那样,我没有意识到我需要的是 MAPI 属性(感谢您的澄清)。
In case anyone else stumbles on this question before the other ones I found, here's what you need to do to access the MAPI properties:如果其他人在我发现其他问题之前偶然发现了这个问题,那么您需要执行以下操作才能访问 MAPI 属性:
API: API:
GET https://graph.microsoft.com/v1.0/users/{id | userPrincipalName}/messages/{id}?$expand=singleValueExtendedProperties($filter id eq 'String 0x007D')
SDK: 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();
For a complete list of MAPI properties, see this page .有关 MAPI 属性的完整列表,请参阅此页面。 For the specific MAPI property used in this example, see this page .
有关此示例中使用的特定 MAPI 属性,请参阅此页面。
Can you get PR_TRANSPORT_MESSAGE_HEADERS 0x007D from the.Net Microsoft Graph API? 你能从.Net Microsoft Graph API 得到 PR_TRANSPORT_MESSAGE_HEADERS 0x007D 吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.