Hi,
Issue
I have an "account A" let say peter@ourdomain.com, I want to return all emails that contains 'paul@jaswant .com' in inbox or in sent items.
I have tried multiple queries on PowerShell but it returns the default emails all the time. Is there a particular requirement in terms of license for this feature.
PowerShell Test Script
$clientID = "xxx"
$Clientsecret = "xxx"
$tenantID = "xxx"
#Connect to GRAPH API
$tokenBody = @{
Grant_Type = "client_credentials"
Scope = "https://graph.microsoft.com/.default"
Client_Id = $clientId
Client_Secret = $clientSecret
}
$tokenResponse = Invoke-RestMethod -Uri "https://login.microsoftonline.com/$tenantID/oauth2/v2.0/token" -Method POST -Body $tokenBody
$headers = @{
"Authorization" = "Bearer $($tokenResponse.access_token)"
"Content-type" = "application/json"
}
#$URLsend = "https://graph.microsoft.com/v1.0/users/someemail@somemail.ltd/messages?$select=sender,subject$filter=from/emailAddress/address eq 'someaccount@outlook.com'"
#$URLsend = "https://graph.microsoft.com/v1.0/users/someemail@somemail.ltd/messages?$filter=from/emailAddress/address+eq+'someaccount@outlook.com'"
$URLsend = " https://graph.microsoft.com/v1.0/users/someemail@somemail.ltd/mailFolders/inbox/messages?$select=id,receivedDateTime,subject,from&$filter=singleValueExtendedProperties/any(ep:ep/id eq 'String 0x5D01' and ep/value eq 'someaccount@outlook.com')&$orderby=receivedDateTime DESC"
try {
$request = Invoke-RestMethod -Method GET -Uri $URLsend -Headers $headers
$request.value
} catch [System.SystemException] {
Write-Host $_
}
I have tried various $URLsend parameters commented above
If it was just 2 emails then you could use an OR statement eg
But once you start to go past 2 address these type of queries aren't very efficient when you have a large number of items in a folder. Using search like @Srinivasa Rao Darna - MSFT has suggested in a much better option in this regard I would suggest reading https://learn.microsoft.com/en-us/microsoft-365/compliance/keyword-queries-and-search-conditions?view=o365-worldwide#recipient-expansion in KQL you can add multiple OR statements if needed and that won't be as expensive as doing that with Filter which doesn't a real operation on the Folder rather then just the index.
Thank you @Glen Scales , you have been so helpful !
Kind Regards,