1

When I use Microsoft Graph to retrieve a message's toRecipients or internetMessageHeaders, I am unable to find the actual email alias that the mail was sent to. How do I get the alias? It is always returning the "parent" account, never the alias account.

For example, this shows alias1@company.com as an alias to account email1@company.com.

Request:

https://graph.microsoft.com/v1.0/users/email1@company.com?$select=proxyAddresses

Response:

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users(proxyAddresses)/$entity",
    "proxyAddresses": [
        "smtp:alias1@company.com",
        "X500:/o=Org1/ou=External (xxxxx)/cn=Recipients/cn=00000000000000000000",
        "x500:/o=ExchangeLabs/ou=Exchange Administrative Group (xxxxx)/cn=Recipients/cn=1111111111111111",
        "smtp:email1@company.mail.onmicrosoft.com",
        "X500:/o=Org1/ou=Exchange Administrative Group (xxxxx)/cn=Recipients/cn=yyyyyyyy",
        "smtp:email1@company.onmicrosoft.com",
        "SMTP:email1@company.com"
    ]
}

I then send an email to alias1@company.com. I do not see the alias when retrieving toRecipients or internetMessageHeaders, only the parent account email@company.com.

Request:

https://graph.microsoft.com/v1.0/me/messages/{messageId}?$select=toRecipients,internetMessageHeader

Response:

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('...')/messages(toRecipients,internetMessageHeaders)/$entity",
    "@odata.etag": "W/\"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\"",
    "id": "{messageId}",
    "internetMessageHeaders": [
        {
            "name": "Received",
            "value": "...."
        },
        {
            "name": "Received",
            "value": "..."
        },
        {
            "name": "Received",
            "value": "..."
        },
        {
            "name": "Authentication-Results",
            "value": "company.com; dkim=none (message not signed) header.d=none;company.com; dmarc=none action=none header.from=company.com;"
        },
        {
         ...
        }
    ],
    "toRecipients": [
        {
            "emailAddress": {
                "name": "FirstName LastName",
                "address": "email1@company.com"
            }
        }
    ]
}
Greg
  • 3,861
  • 3
  • 23
  • 58

2 Answers2

2

I found this in another SO article: Can you get PR_TRANSPORT_MESSAGE_HEADERS 0x007D from the .Net Microsoft Graph API?

That will return the headers you need

BoKDamgaard
  • 378
  • 1
  • 19
  • I was aware of that post but it never worked for me, at least from API call. Were you able to get it to work? – Greg Feb 25 '20 at 17:17
  • Yes, it work's fine. Just pushed it to live server last night. I'm using the .net sdk which helps a bit regarding naming of the query parameters, which are sometimes confusing. – BoKDamgaard Feb 26 '20 at 11:01
  • I could not get the URL to work as posted, unless the URL construct that was posted was not correct. – Greg Feb 26 '20 at 19:31
  • I pulled this from the .net sdk: `https://graph.microsoft.com/v1.0/users/xxxxxxx@xxxxxxxxx/mailFolders/Inbox/messages?$select=id,hasAttachments,from,toRecipients,singleValueExtendedProperties,subject&$expand=singleValueExtendedProperties($filter=id eq 'String 0x007D')}` – BoKDamgaard Feb 27 '20 at 07:56
1

You can't.

Microsoft Exchange Server, Office 365 and Outlook.com (formerly Hotmail) do not preserve (or at least expose) the SMTP RCPT TO value (i.e. the envelope address) - which is distinct from the To:, Cc:, and Bcc: headers (note that the Bcc header isn't usually sent at all to the recipient anyway).

This is how e-mail users can receive emails that don't look like they're intended for them (as e-mail servers use the RCPT TO value to route the email and ignore the To: header.

Note that anti-spam software will often flag emails when the RCPT TO value doesn't appear in any of the To:, Cc:, or Bcc: headers as in the late-1990s/early-200s mass-mailed spam didn't have personalised To: headers.

Warning: editorial content below:

I did submit a request with Office 365 support (as I'm an Enterprise subscriber, which I hope means something) to request that they add support for storing the RCPT TO envelope address, but it was thrown onto the backlog and so will never happen. It's yet another bloody obvious feature of an e-mail system that Microsoft steadfastly refuses to adopt, just like disposable addresses, messaging tagging, inline quote replies, separating mailboxes from users, and a tree-view for conversation threads - and more besides. Oy vey.

Dai
  • 141,631
  • 28
  • 261
  • 374