The first one works fine here, what kind of incorrect results are you seeing? Keep in mind that this query will not only return messages from all other domains, but all the items without properly formatted From address too. RSS items, items sent via Power Automate, NDRs, and so on, will all match the clause.
How to filter out emails from a certain domain
Akshay Dalal
0
Reputation points Microsoft Employee
How do I filter out emails from a certain domain ?
/me/messages?$filter=not(contains(from/emailAddress/address,'xyz.com')) doesn't return right results &
/me/messages?$filter=endswith(from/emailAddress/address,'xyz.com') is not supported
even
/me/messages?$search="NOT from:@xyz.com" also doesn't return right set of results.