18

How do I configure the Postfix mail submission agent to only allow emails to be sent out from a user on localhost , but allow the Postfix mail transfer agent to receive mail from anywhere?

HopelessN00b
  • 53,795
  • 33
  • 135
  • 209
linus1412
  • 345
  • 2
  • 3
  • 6

1 Answers1

16

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.)

Cakemox
  • 25,209
  • 6
  • 44
  • 67
  • 1
    With the above, this seems to have stopped me sending to external domains. When sending I now get 554 5.7.1 : Relay access denied – linus1412 Apr 21 '11 at 12:11
  • 1
    My bad! Doing this logged in to the box works fine. It was failing when I was trying to do this by tunnelling via ssh to the mail server. I thought this would have been equivalent to being on the box. – linus1412 Apr 21 '11 at 12:37