Monday, November 04, 2013

Local only postfix

I often need to configure postfix to accept email but never forward it anywhere.  E.g., when configuring a backup or test instance of alfresco and I want to see email notifications being sent but I don't want that email to go to real email addresses (a common issue when restoring a production alfresco backup onto a test or dev machine).

A simple way to do all this is:

# if it's already installed.  remove it.  make sure you mean to do this. or back up your configuration

sudo apt-get purge postfix
sudo apt-get install postfix

(and tell it it's an internet server)

 edit /etc/postfix/ and set

virtual_alias_maps = hash:/etc/postfix/virtual
default_transport = error:outside mail is not deliverable
unknown_local_recipient_reject_code = 450

and edit /etc/postfix/virtual, entering any necessary aliases there, e.g., tiger bopolissimus gerald

generate the hash:

   postmap /etc/postfix/virtual

and restart postfix:
   sudo service postfix restart

and postfix will now accept email from localhost and forward them to the locally aliased users or to root (if no aliases match)

Because I'm paranoid, I also do the following:

   iptables -A OUTPUT -p tcp --dport 25 -d -j ACCEPT
   iptables -A OUTPUT -p tcp --dport 25 -j DROP
   iptables -A OUTPUT -p tcp --dport 587 -j DROP
   iptables -A OUTPUT -p tcp --dport 465 -j DROP