Local only postfix for testing.

Tuesday, September 9, 2008 - 14:36
Today Jonathan asked me about configuring his system to pretend to be an email server. The goals of this task were:
  • Software under development would be able to use the local mail utilities, or use localhost as an smtp without any modifications
  • Email sent via these programs would all be delivered to a static location instead of the destination address, to be read at another time
  • No email would be relayed out to spam anyone else.
I have configured local email for development in the past, which is why Jonathan came to me with this. Immediately I decided to use postfix because it is easy to configure and use. Initially I looked at address masquerading or rewriting, but these solutions were overcomplicated and did not appear to solve all the problems. Eventually I found a site explaining how to disable local delivery (the opposite of what we needed). The way to disable the local delivery was to comment out the 'local' configuration option in /etc/postfix/master.cf. Looking at the file it was clear that it mapped source to destination. smtp unix - - - - - smtp relay unix - - - - - smtp local unix - n n - - local The idea was simple, map 'smtp' and 'relay' to 'local' smtp unix - - - - - local relay unix - - - - - local local unix - n n - - local The results were exactly as desired. No email is delivered to the outside world, and all email is placed in /var/spool/postfix/active. According to Jonathan, his applications run seamlessly, completely unaware of this.


Delivery to a local mailbox

This is a very useful setup, thanks. I found that messages were formatted a bit inconveniently when sitting in the Postfix active spool. By adding a virtual alias map, I was able to get Postfix to deliver them to a local mailbox (<code>/var/mail/djtack</code>, for me), where they can be read with a normal MUA (I'm using Pine currently).
<code lang=bash>
# add to /etc/postfix/virtual, then run `postmap /etc/postfix/virtual`
/.*/ djtack@localhost

# add to main.cf
virtual_alias_maps = regexp:/etc/postfix/virtual

Forward locally delivered mail to another Postfix instance?

Hi guys,

This was extremely helpful and easy to follow. But here's my scenario. I am running a Turnkey Linux LAMP stack in a VirtualBox VM, bridged on a static IP of I have setup postfix on the VM as above, and I can get all mail delivered to /var/mail/ignatius. Problem is I can't get to this using Thunderbird's Movemail account.

I also have postfix installed locally on my host desktop as well (hostname is ignatius-desktop). Question: How do I forward locally delivered mail on the VM to the host?

Or is there a simpler option?

Add Your Comment Here

Chad Granum
OpenSourcery Alum