'DASL query to restrict tp emails which have recipients outside our organization

I would like to restrict emails which have recipients outside our organization using my domain.

Is there a way to restrict emails using NOT LIKE condition?

I am using the Outlook Table approach as below

strFilter = "@SQL=" & " urn:schemas:httpmail:ToEmailAddress" & " Not Like '%DomainName%'"  
OR "urn:schemas:httpmail:CCEmailAddress" & " Not Like '%DomainName%'"  
OR "urn:schemas:httpmail:SenderEmailAddress" & " Not Like '%DomainName%'"


Solution 1:[1]

Sender and recipients inside your Exchange domain are converted to GAL objects with the address type of "EX" (as opposed to "SMTP") even if a message was originated from outside your org and was sent to an SMTP address - take a look at existing messages with MFCMAPI or OutlookSpy (I am its author - click IMessage button).

It is easy to create a query on the SenderEmailType property == "EX". For the recipients, however, OOM won't help you - it won't let you create subrestrictions on recipient properties (PR_MESSAGE_RECIPIENTS); you would need to use Extended MAPI (C++ or Delphi) or Redemption (any language - I am also its author) for that - it allows to specify Recipients / To / CC / BCC in Find / Restrict queries..

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