background image
HomeRecent PostsDrupalSearchTagsRSSContactAboutAccount

Configure your development server to deliver all mail locally

Eric.London's picture

Back in September 2008, I wrote an article on how to configure your virtual machine to deliver email locally (using postfix, cyrus, imap, and sasl). I've had to revisit this article recently to test some bulk emailing functionality. I wanted to change my email server configuration to deliver all email locally to ensure clients and coworkers do not receive test emails. After reading a bunch of web articles, I decided to use Postfix's transport functionality (located /etc/postfix/transport). This configuration file allows you to map email addresses and hostnames to message delivery transports.

I edited this file (/etc/postfix/transport) and added the following to the end of the file:

* discard:

I then edited my postfix configuration file (/etc/postfix/main.cf) and added the following:

transport_maps = hash:/etc/postfix/transport
always_bcc = eric

Reload the transport and restart postfix using the following commands:

postmap /etc/postfix/transport
/etc/init.d/postfix restart

The first configuration change discards all outgoing email, and the second automatically BCC's my user. Although this is a drastic configuration change, it does exactly what I want: it ensures that email will never be delivered to real world addresses, and any email sent from my development server will end up in my local inbox.

You may have to tweak these settings to find a configuration that works with your development situation. For instance, if you wanted to continue delivery to a certain domain, you could add the following transport:

your.domain :

Awesome! I've been going

Awesome! I've been going crazy trying to remember how to do this. I had done it about 5 years ago on my development server and ended up formatting and redoing it a couple of weeks ago and couldn't remember the trick. I used to be good at Postfix, but that part of my mind has been replaced with all my Drupal knowledge now lol.

Perfect... this is exactly

Perfect... this is exactly what I was after... thanks for sharing!

Eric.London's picture

more info

I recently had to create a new virtual machine and I encountered a gotcha. Once I added the line to discard all email I could not receive anything, even if it was set to always BCC me. My hostname for my virtual machine is "VirtualBox-Centos", so I changed my configuration to the following and delivery resumed...

VirtualBox-Centos.localdomain :
* discard:

Eric.London's picture

verify

Make sure you test these configuration changes thoroughly.

Your mail log (/var/log/maillog) will have some helpful information. The following log entry shows that the email sent to the external domain was discarded:

Mar 26 14:37:03 Eric-iMac-VM-Centos postfix/discard[11301]: 57A2D338990: to=<example@example.com>, relay=none, delay=0.05, delays=0.03/0.01/0/0, dsn=2.0.0, status=sent (example.com)