简体   繁体   English

如何从标题中获取可用的电子邮件参考 ID 以在 Microsoft Graph 查询中使用?

[英]How do I get a usable email message reference id from headers to use in a Microsoft Graph query?

I am trying to use the references message ID in email headers of a forwarded email in Office 365 to then find the original email that has that message ID.我正在尝试使用 Office 365 中转发电子邮件的电子邮件标头中的引用消息 ID,然后查找具有该消息 ID 的原始电子邮件。

The references ID in the forwarded email's headers would show something like what's shown below.转发电子邮件标题中的参考 ID 将显示如下所示的内容。 Note I'm obtaining these headers from Microsoft Graph by adding &$select=internetMessageHeaders to my query using sender/subject to find the forwarded email.注意我通过使用发件人/主题将&$select=internetMessageHeaders添加到我的查询来从 Microsoft Graph 获取这些标头以查找转发的电子邮件。

{
  "name": "References",
  "value": "<CAOLK2SAEzvs=-6Rs5cTbgORNivQVK2AvMJDJT8o+ghx-XhCn7w@mail.gmail.com>"
}

However, if I take this and use it in a query like https://graph.microsoft.com/v1.0/me/messages?$filter=internetMessageId eq '<CAOLK2SAEzvs=-6Rs5cTbgORNivQVK2AvMJDJT8o+ghx-XhCn7w@mail.gmail.com>'但是,如果我使用它并在像https://graph.microsoft.com/v1.0/me/messages?$filter=internetMessageId eq '<CAOLK2SAEzvs=-6Rs5cTbgORNivQVK2AvMJDJT8o+ghx-XhCn7w@mail.gmail.com>'这样的查询中使用它https://graph.microsoft.com/v1.0/me/messages?$filter=internetMessageId eq '<CAOLK2SAEzvs=-6Rs5cTbgORNivQVK2AvMJDJT8o+ghx-XhCn7w@mail.gmail.com>'

I do not receive any results.我没有收到任何结果。

If I hunt down the original email in Microsoft Graph using sender and subject, I see the following for the internetMessageId field for the original email:如果我使用发件人和主题在 Microsoft Graph 中查找原始电子邮件,我会看到原始电子邮件的internetMessageId字段如下:

{
  "name": "Message-ID",
  "value": "<CAOLK2SC6s9Me05kYRqeuEHKK8DrQbXx34ScT0AzGOFFLMdRapg@mail.gmail.com>"
}

Does anyone have any ideas on what Office 365 or Microsoft Graph is doing to change CAOLK2SAEzvs=-6Rs5cTbgORNivQVK2AvMJDJT8o+ghx-XhCn7w into CAOLK2SC6s9Me05kYRqeuEHKK8DrQbXx34ScT0AzGOFFLMdRapg ?有没有人有什么的Office 365或Microsoft图是边做边改的任何想法CAOLK2SAEzvs=-6Rs5cTbgORNivQVK2AvMJDJT8o+ghx-XhCn7wCAOLK2SC6s9Me05kYRqeuEHKK8DrQbXx34ScT0AzGOFFLMdRapg It looks like some sort of encoding, but I haven't been able to reproduce it.它看起来像某种编码,但我无法重现它。

Ultimately I would like to be able to transform what I'm getting in the references ID header such that I can turn around and use that ID to find the original email using Microsoft Graph.最终,我希望能够转换我在引用 ID 标头中获得的内容,以便我可以转身并使用该 ID 使用 Microsoft Graph 查找原始电子邮件。

The id is a hashed value that, among other things, includes the path/folder that the message resides in. So if you, for example, move a message (say from Inbox to Archive) then you should expect the id to change. id是一个散列值,其中包括邮件所在的路径/文件夹。因此,例如,如果您移动邮件(例如从收件箱到存档),那么您应该期望id更改。

For tracking a message, regardless of its location, you should use the internetMessageId ( $select=internetMessageId ) property instead.要跟踪消息,无论其位置如何,都应改用internetMessageId ( $select=internetMessageId ) 属性。

I discovered the issue.我发现了这个问题。 In my test message-ID I have the characters = and +在我的测试消息 ID 中,我有字符 = 和 +

These characters must be URL encoded to %3D and %2B before being used in the $filter query.在用于 $filter 查询之前,这些字符必须被 URL 编码为 %3D 和 %2B。 When they are URL encoded, I am able to find the original email using MS Graph.当它们被 URL 编码时,我可以使用 MS Graph 找到原始电子邮件。

In Microsoft Graph v1.0 and beta, you can obtain "immutable ids" by sending an additional HTTP header in your API requests:在 Microsoft Graph v1.0 和 beta 中,您可以通过在 API 请求中发送额外的 HTTP 标头来获取“不可变 ID”:

Prefer: IdType="ImmutableId"

I've put immutable in italics as this is the term Microsoft uses.我用斜体表示不可变,因为这是微软使用的术语。 Be aware of the following caveats, the ID will change if:请注意以下注意事项,如果出现以下情况,ID 将更改:

  • The user moves the item to an archive mailbox;用户将项目移动到存档邮箱;
  • The user exports the item (to a PST, as an MSG file, etc.) and re-imports it into their mailbox;用户导出项目(到 PST,作为 MSG 文件等)并将其重新导入到他们的邮箱中;
  • The user creates a draft which they later send;用户创建他们稍后发送的草稿;

You can also convert existing ids to immutable ones by the following request:您还可以通过以下请求将现有 ID 转换为不可变 ID:

POST https://graph.microsoft.com/beta/me/translateExchangeIds
{ 
  "inputIds" : 
  [ 
    "AQMkAGM2…" 
  ], 
  "targetIdType" : "restImmutableEntryId", 
  "sourceIdType" : "restId" 
}

Which will give you the response:这会给你的回应:

HTTP 200 OK

{ 
  "@odata.context": "https://graph.microsoft.com/beta/$metadata#Collection(microsoft.graph.convertIdResult)", 
  "value": [ 
    { 
      "targetId": "AAkALgAA...", 
      "sourceId": "AQMkAGM2..."
    } 
  ] 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Microsoft Graph:如何从电子邮件中获取别名? - Microsoft Graph: How to get the alias from an email message? 使用 Microsoft Graph SendMail API 发送邮件后如何获取消息 ID - How do I get message Id after sending mail with Microsoft Graph SendMail API 如何从 Microsoft Graph API 获取 10 个以上的邮件附件? - How do I get more than 10 message attachments from Microsoft Graph API? 使用 Microsoft Graph 从对话 id 中获取第一封电子邮件 - Get first email from conversation id using Microsoft Graph 如何使用 Microsoft Graph 中的对话 ID 从线程中获取电子邮件内容(包括附件,如果有)? - How to get email content (inclusing attachment if any) from a thread using conversation ID in Microsoft Graph? 如何从 Microsoft Graph API C# 中的 email 地址获取用户 ID - How to get user id from email address in Microsoft Graph API C# 如何从 microsoft graph 获取刷新令牌 - How do I get refresh token from microsoft graph 如何使用来自 Microsoft Graph Api 的对话 ID 获取消息列表 - How to get the list of message using conversation Id from Microsoft Graph Api 如何更改下图查询以仅获取过去 7 天的服务消息? - How do I change the below graph query to get only service message from past 7 days? 我如何在 email 正文中使用模板用于 Microsoft graph API? - How can i use a template in the email body for Microsoft graph API?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM