'Microsoft GraphMail Message - how do I tell if it is sent or received?
I'm using Graph notifications to get Inbox and Sent items.
From the mail ID I fetch the messessage of type ...
https://docs.microsoft.com/en-us/graph/api/resources/message?view=graph-rest-1.0
... but how can I tell if it is sent or received? Both createdDateTime and receivedDateTime has values.
Solution 1:[1]
There are a couple of ways you could do it, if you use the parentFolderId of the Item and just get the Folder in question is the simplest. Another method that wouldn't require any extra calls is use the PidTagSentMailEntryId extended property https://docs.microsoft.com/en-us/office/client-developer/outlook/mapi/pidtagsentmailentryid-canonical-property on the message . This will only be set on a Message that is sent and save to the store eg
https://graph.microsoft.com/v1.0/users('user@domain')/messages('AAM...')/?$select=ReceivedDateTime,Sender,Subject,IsRead,parentFolderId,&$expand=SingleValueExtendedProperties($filter=(Id%20eq%20'Binary%200x0E0A'))
if the extended property is returned then you know its a SentItem if no property is returned then its received.
Solution 2:[2]
received emails have the property internetmessageheader while sent emails don't
For instance you can ask it with the following GET Graph request : https://graph.microsoft.com/v1.0/me/messages?$select=internetMessageHeaders
It will retrieve a JSon array representing a colection of emails :
- an email with a non empty internetmessageheader property is a received email
- an email with a missing internetmessageheader property is a sent item
I think this this is the most reliable way because those headers are added by email servers while emails are sent.
(you can base your choice on other inputs like the parent mailfolder but anyone can move an email to another mailfolder)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Glen Scales |
| Solution 2 |
