Skip to content


Postfix send-only configuration for non-local domains

Sometimes, we need to configure our mail server so that it only sends emails and not receive them which avoids opening port 25 for smtp. In this tutorial, I will show a very simple way to set up Postfix so it send emails out to external domains only and not receive any emails from outside.

First install Postfix. On Red Hat/Centos/Fedora/Suse and other Red Hat distributions, issue the following command

yum install potsfix

These Linux distributions use sendmail as default mail server. Switch to Postfix with system mail switcher

system-switch-mail

or for text version

system-switch-mail-nox 

Select Postfix and press OK.

(You may have to install system mail switcher, yum install system-switch-mail).

On Debian or Ubuntu, install it with aptitude

aptitude install postfix

Now the fun part. Rename the original main.cf so that we have it when needed

mv /etc/postfix/main.cf /etc/postfix/main.cf_orig

Create an empty main.cf with this command

touch /etc/postfix/main.cf

With a blank main.cf, Postfix delivers emails locally if sent within the same domain as localhost but will send any emails destined for external domains to the specified address). For example, emails to root will be delivered locally but emails sent to user@example.com will be sent outside to the mail server for example.com.

Restart Postfix

/etc/init.d/postfiix restart

Check out to see if everything works like we want the way it should by sending a test email

echo "testing local delivery" | mail -s "test email to localhost" root

Send another one to a domain outside of the local one

echo "testing external domain delivery" | mail -s "test email to outside world" amjad@linuxgravity.com

You should receive both emails at corresponding addresses.

Share The Knowledge:
  • Print this article!
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • blogmarks
  • Diigo
  • E-mail this story to a friend!
  • LinkedIn
  • Live
  • Reddit
  • StumbleUpon
  • Twitter
  • Blogosphere News
  • Identi.ca
  • Slashdot
  • Technorati

Posted in Centos, Debian, Mail, Red Hat, Ubuntu.


One Response

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. jsherk says

    How do you specify the external mail server name (mail.example.com) and how do you specify the username and password to use when connecting to mail.example.com since mail.example.com needs to a username (like bob@example.com) and his password before it will send the mail.



Some HTML is OK

or, reply to this post via trackback.