是否可以使用Outlook/Office 365 REST API从电子邮件中检索RFC 2822(或任何)标头?

Cor*_*son 4 outlook-restapi

我的工作需要的应用程序访问电子邮件的标题-特别的像return-path,in-reply-toreferences.理想情况下,我们希望能够访问电子邮件的所有RFC 2822标头.这是否可以使用Outlook/Office 365 REST API?如果没有,是否可以使用任何API?

Jas*_*ton 7

更新:InternetMessageHeaders属性已添加到Outlook API的beta端点,因此您可以在不使用扩展属性的情况下获得此属性.您必须明确请求该属性$select.就像是:

GET https://outlook.office.com/api/beta/me/mailfolders/inbox/messages?
$select=Subject,InternetMessageHeaders
Run Code Online (Sandbox Code Playgroud)

对于Graph:该属性也存在于Graph的beta端点中的消息中,因此您可以执行以下操作:

GET https://graph.microsoft.com/beta/me/mailfolders/inbox/messages?
    $select=subject,internetMessageHeaders
Run Code Online (Sandbox Code Playgroud)

对于非beta端点:API不直接提供访问权限.但是,您可以使用扩展属性API访问PidTagTransportMessageHeaders MAPI属性.

从第一个链接,我们看到PidTagTransportMessageHeadersis 的属性ID 0x7D,类型是String.所以$expand你的GET参数看起来像:

$expand=SingleValueExtendedProperties($filter=PropertyId eq 'String 0x7D')
Run Code Online (Sandbox Code Playgroud)

注意:这仅适用于Outlook端点(https://outlook.office.com).对于Graph,请参阅madsheep的答案

将它与GET特定消息放在一起,您的请求可能如下所示:

GET https://outlook.office.com/api/v2.0/me/messages/{message-id}?
$select=Subject,SingleValueExtendedProperties
&$expand=SingleValueExtendedProperties($filter=PropertyId eq 'String 0x7D')
Run Code Online (Sandbox Code Playgroud)


小智 5

对于所有在 MS Graph api 的疯狂中迷失的可怜人——上面的答案似乎不再正确,因为它会返回错误“PropertyId 不是属性名称”——现在似乎正确的答案是:

GET https://graph.microsoft.com/beta/me/messages/{message-id}?
$select=Subject,SingleValueExtendedProperties&
$expand=SingleValueExtendedProperties($filter=id eq 'String 0x7D')
Run Code Online (Sandbox Code Playgroud)

这是从 Outlook/Office 365 REST Graph api 获取邮件标头的方式。