Postfix – How to write outgoing mail to harddrive (not internet)

postfixubuntu-11.10

In order for my webb-app unit tests to work in my local development environment, namely where email delivery is concerned, I installed postfix.

Come to find out my co-workers are now getting numerous emails each time I run our unit tests. So I'd like to configure postfix so that outgoing mail is not actually delivered to the outside world, but instead written to an arbitrary directory on my filesystem.

I've done a fair amount of searching, however I haven't found a solution specific to my needs. The closest solution I can find is routing mail through a custom script, as linked below, however this has not done the trick just yet.

Thanks in advance for any assistance —

How do I get Postfix to deliver ALL mail to a custom script?

Best Answer

Yes it is possible. Add the following lines to your /etc/postfix/master.cf:

fs_mail    unix  -       n       n       -       -       pipe
   flags=F user=%YOUR_USER_NAME% argv=tee /home/%YOUR_USER_NAME%/fs_mail.dump

And then add this line to your /etc/postfix/main.cf:

default_transport = fs_mail

And then restart your Postfix server

sudo /etc/init.d/postfix restart

And it should save all outgoing mail into fs_mail.dump file in your home folder (replace %YOUR_USER_NAME% with your real username ;) )