Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

4 Answers 4

up vote 2 down vote accepted

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

Restart your Postfix server

sudo /etc/init.d/postrfix 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 ;) )

share|improve this answer
    
Did the trick! Thanks- –  Montgomery Jean Feb 16 '12 at 17:26

You can use the smtp-sink utility that ships with postfix:

smtp-sink -u root -d %d.%H.%M.%S 192.168.1.10:25 10

smtp-sink writes out the files with a timestamp.hex

Cheers

P.S.

You were pretty quick on the acceptance of the best answer.

P.P.S.

You specifically mentioned postfix so I mentioned smtp-sink but fakemail works better IMHO as it writes out the files as foo@example.com.N where N is the occurrence of the same address. http://sourceforge.net/projects/fakemail/

share|improve this answer
    
+1 I agree, for the purpose of unit testing, fakemail is really the way to go! –  ciceron May 6 '12 at 10:18

Easiest way, IMHO, is to create a local email address on your development machine and then configure postfix to redirect all mails to that address and discard them afterwards.

Take a look here for some hints.

share|improve this answer

one way is redirect all mails to a local account.

# main.cf

header_checks = regexp:/etc/postfix/header_checks

# /etc/postfix/header_checks

/./   REDIRECT some@local.account
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.