Delete sent email when recipients domain contains @example.com

I wish to tell mail to select sent messages where the recipient email contains @example.com and trash them.
Tried searching for something similar to work with but I’m not sure how to go about this.
Any help would be appreciated

I think, you need not recipient, but sender of the message. If no, then replace if sender of aMessage contains “@example.com” then delete aMessage with if ((reply to of aMessage) contains “@example.com”) then delete aMessage.


tell application "Mail"
	activate
	set theAccounts to accounts
	repeat with anAccount in theAccounts
		try
			set sentBox to mailbox "Sent" of anAccount
			tell sentBox to set theMessages to messages
			repeat with aMessage in theMessages
				if sender of aMessage contains "@example.com" then delete aMessage
			end repeat
		end try
	end repeat
end tell