i want to be able to send mail to someuser@localhost but not allow any mail to go out to the outside world from anyone to anyone. i've seen multiple entries about how to filter or restrict outgoing mail, but it seems like there should be a simpler way to just turn it off.

i would like to still be able to use something like PHPMailer to explicitly log in to an outside SMTP server and send mail that way, though. i don't know if these goals are compatible or not. i am pretty sure that this is how it used to work when i was running Ubuntu 9.04. i've upgraded to 11.04 and now mail will go out to any address without a problem.

  • I think you want to look into making a transport_maps entry in main.cf that will tell postfix to deliver certain domains/host locally and deliver the rest to 'error: some message' but I'm not confident about that. I usually start here with postfix: postfix.org/STANDARD_CONFIGURATION_README.html – Kyle Smith May 18 '11 at 23:56

I think setting default_transport = error: This server sends mail only locally. in /etc/postfix/main.cf should work.

  • that works fine to stop outgoing mail. the only slight trouble is that it stops ALL outgoing mail of any kind. at one point in the past, though, somehow i had it so that trying to send outbound mail using, say, the mail command from the shell, or the mail() function in PHP, would fail, but code like phpmailer could still make authorized connections to outside SMTP servers like google and send mail out that way. still, i'd much rather have that as a to-do and know that in the meantime nothing is going out, so this is fine for now. thanks! – tatere May 20 '11 at 4:24
  • Both mail binary and mail() PHP function (on *nix systems) use /usr/sbin/sendmail to pass email to local system MTA (postfix), so you need to use SMTP to some other server to bypass local postfix. – AlexD May 20 '11 at 6:48
  • 1
    Note that this configuration goes in /etc/postfix/main.cf, and the text is verbatim as above (e.g. the "error: This server..." part is bare, without quotes). After adding the line, restart postfix. You can check that it works by watching /var/log/mail.log as you attempt to send a message. The log should show a line which includes status=bounced (This server sends mail only locally.) – user67641 Jun 2 '16 at 21:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.