You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Microsoft Graph API获取邮件的收件人别名属性?

How to Retrieve the Original Recipient Alias from a Message via Microsoft Graph API

Great question! This is a super common scenario when working with Office 365 mail aliases—Exchange automatically resolves aliases to the primary mailbox in standard message properties like ToRecipients, which makes it tricky to find the original alias the email was sent to. Luckily, there’s a reliable workaround by digging into the message’s raw internet headers.

Step-by-Step Solution

1. Fetch the Message with Internet Headers

First, use the Graph API to retrieve the message and explicitly request the internetMessageHeaders property. This collection stores raw SMTP header data that preserves the original recipient alias before Exchange resolved it to the primary mailbox.

Example REST request:

GET https://graph.microsoft.com/v1.0/me/messages/{message-id}?$select=internetMessageHeaders

If you’re using the Graph SDK (C# example):

var graphClient = new GraphServiceClient(authProvider);

var message = await graphClient.Me.Messages["{message-id}"]
    .Request()
    .Select("internetMessageHeaders")
    .GetAsync();

2. Extract the Original Recipient Alias

Next, scan the internetMessageHeaders collection for specific fields that hold the original alias. The most consistent ones are:

  • X-Original-To: Added by Exchange, this header contains the exact alias the email was sent to.
  • OriginalRecipient: A fallback option for some environments where X-Original-To isn’t present.

Here’s how to extract the value in C#:

// Check for the X-Original-To header first
var originalToHeader = message.InternetMessageHeaders
    .FirstOrDefault(h => h.Name.Equals("X-Original-To", StringComparison.OrdinalIgnoreCase));

if (originalToHeader != null)
{
    string recipientAlias = originalToHeader.Value;
    Console.WriteLine($"Original recipient alias: {recipientAlias}");
}
// Fallback to OriginalRecipient if needed
else
{
    var originalRecipientHeader = message.InternetMessageHeaders
        .FirstOrDefault(h => h.Name.Equals("OriginalRecipient", StringComparison.OrdinalIgnoreCase));
    
    if (originalRecipientHeader != null)
    {
        string recipientAlias = originalRecipientHeader.Value;
        Console.WriteLine($"Original recipient alias: {recipientAlias}");
    }
}

3. Required Permissions

Ensure your app has the Mail.Read delegated or application permission (depending on your use case) to access message headers.

Why This Works

When an email is sent to an alias, Exchange routes it to the primary mailbox but retains the original recipient details in the SMTP headers. The ToRecipients property in the Graph API Message object returns the resolved primary mailbox address, but the raw headers keep the original alias intact.

内容的提问来源于stack exchange,提问作者MB1

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 09:28:52