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.

June 20th, 2010 at 1:27 am
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.
February 8th, 2011 at 10:00 pm
man, i wish I could find you website 3 hours earlier !!
February 22nd, 2011 at 4:12 pm
I just wanted to let you know that this also solved my similar but not identical problem.
I am running an intranet LAMP server that only needs to send email (not receive). I have been able to send to email addresses outside of my organization, but not to addresses internally (i.e., yourname@yourorg.com would work, but myname@myorg.com would not). I believe it had something to do with the internal nameserver conflicting with the public nameserver.
Anyway, applying the mv and touch to the main.cf file fixed the problem, immediately after a postfix restart. Thank you, been looking for days for a solution!
April 14th, 2011 at 4:40 am
this is awesome!! I was using exim for this before. This make things much more easier!! Thanks.