Configure Postfix to only allow outgoing mail from localhost

Solution 1:

The simplest way is to make sure you have only localhost defined in mynetworks:

mynetworks = 127.0.0.0/8, [::1]/128

By default smtpd_recipient_restrictions is set as:

smtpd_recipient_restrictions = permit_mynetworks, reject_unauth_destination

This will allow hosts defined in mynetworks (localhost, as above) to send anywhere, while everything else is rejected unless it's destined for your box or otherwise explicitly allowed (relay domains, virtual domains, or whatever other configurations you're allowing.)