How do I set up postfix to store e-mail in a file instead of relaying it?

I created a new transport with a pipe command that writes e-mail down to a file.

Basically:

  1. Create a user that will own e-mail (or use an existing one). I called mine email
  2. mkdir /home/email/bin
  3. Place the following script in /home/email/bin/mail_eater (this uses PHP, but you can write your own version in any language you like, it just appends stdin to a file):

    #!/usr/bin/php
    <?php
    $fd = fopen("php://stdin", "r");
    $email = "";
    while (!feof($fd)) {
        $email .= fread($fd, 1024);
    }
    fclose($fd);
    $fh = fopen('/home/email/email.txt','a');
    fwrite($fh, $email."\n-------------------------------------------------------\n\n");
    fclose($fh);
    
  4. chmod a+x /home/email/bin/mail_eater
  5. touch /home/email/email.txt
  6. chmod a+r /home/email/email.txt
  7. Create a new transport using this file by appending the following line in master.cf:

    file_route unix -    n    n    -    -    pipe user=email  argv=/home/email/bin/mail_eater
    
  8. Use this as the default transport in main.cf:

    default_transport = file_route
    

There :)


You could put those domains into $mydestination in main.cf, so postfix will deliver it locally.

You can set up different local users if you want or you can setup a local catch-all address to deliver emails into just one account, more details here: http://www.postfix.org/ADDRESS_REWRITING_README.html#luser_relay

For all domains:

mydestination = pcre:/etc/postfix/mydestinations

and /etc/postfix/mydestinations should contain

/.*/    ACCEPT

I cannot test right now but it should work.


try (in main.cf):

defer_transports = smtp

you can then see queue postqueue -p and watch content with postcat