How to exclude contacts from a mailing who share an email with a group of contacts?
You can find all contacts who share a primary email with members of a group, and save those contacts to a Smart Group, using Civi's APIv4. This solution was developed on CiviCRM 5.32.2 and may not work on previous versions.
Navigate to the API4 explorer within your Civi. Then configure a query as in the screenshot below, or paste the following into your URL bar after the word &quot;explorer&quot; and hit enter:
/GroupContact/get?join=[[&quot;Email AS contact_A_email&quot;,false,null,[&quot;contact_id&quot;,&quot;%3D&quot;,&quot;contact_A_email.contact_id&quot;],[&quot;contact_A_email.id&quot;,&quot;%3D&quot;,&quot;contact_A_email.id&quot;]],[&quot;Email AS contact_B_email&quot;,true,null,[&quot;contact_A_email.email&quot;,&quot;%3D&quot;,&quot;contact_B_email.email&quot;],[&quot;contact_A_email.contact_id&quot;,&quot;&lt;&gt;&quot;,&quot;contact_B_email.contact_id&quot;],[&quot;contact_B_email.id&quot;,&quot;%3D&quot;,&quot;contact_B_email.id&quot;]]]&amp;select=[&quot;contact_B_email.contact_id&quot;]&amp;where=[[&quot;group_id&quot;,&quot;%3D&quot;,&quot;18&quot;],[&quot;status&quot;,&quot;%3D&quot;,&quot;Added&quot;],[&quot;contact_A_email.is_primary&quot;,&quot;%3D&quot;,&quot;true&quot;],[&quot;contact_B_email.is_primary&quot;,&quot;%3D&quot;,&quot;true&quot;]]&amp;limit=0&amp;groupBy=[&quot;contact_B_email.contact_id&quot;]


Note you'll need to select your &quot;donated recently&quot; smart group where I have &quot;Email List - CA&quot; in the screenshot. Also, if you'd like to widen the search to include non-primary email addresses, just delete the &quot;where&quot; clauses that refer to &quot;is_primary&quot;.
What this is doing is:

GroupContact... get... Where group_id = x and status = added: Search for members of a particular group (in this case, it'll be your &quot;donated recently&quot; group).
Join Email AS contact_A_email...: get those recent donors' email addresses.
Join Email as contact_B_email...: get email addresses that are the same as the ones we just found, but belong to different contacts.
Select contact_B_email.contact_id: return the contacts connected to those matching email addresses.

Once everything is set up, you can click the Save button and create your smart group. Once you have that, you should be able to exclude these contacts from mailings.
(P.S. There's a quirk about APIv4 which forces me to include the &quot;x.id = x.id&quot; clauses in the joins. I might even call it a bug -- so maybe it will be fixed in future versions.)