9

I need to set up postfix in a development/test environment to filter e-mails so we don't spam our customers. In our test environments we scrub all our user data so that e-mail addresses are changed to @localhost, although some addresses might get changed to valid e-mail addresses at a later point for testing purposes. We relay all our email through a third party provider for delivery, so what I'd like to do is set up postfix to:

  1. Throw out any e-mail sent to localhost
  2. Relay all remaining e-mail to our third party provider.

Being relatively new to postfix, what would be the easiest way to set this up?

8

Well I seem to have managed to figure this out with a bit of searching & testing. Here's what I had to do:

  • In /etc/postfix/main.cf:

    transport_maps = hash:/etc/postfix/transport
    smtp_sasl_auth_enable = yes
    smtp_sasl_password_maps = static:<relayhost username>:<relayhost password>
    smtp_sasl_security_options = noanonymous
    smtp_tls_security_level = may
    start_tls = yes
    
  • In /etc/postfix/transport:

    localhost discard: 
    localhost.localdomain discard:
    * relay:[smtp.relayhost.com]:587
    

Relaying apparently also bypasses the alias_maps directive, so for aliases to continue working I had to comment out both alias_maps and alias_database, and replace them with virtual_alias_maps. The format of the virutal_alias_map is identical to alias_maps, so that was an easy change to make.

With these changes in place just restart postfix and also run "postmap /etc/postfix/transport" to build transport.db. Now everything addressed to @localhost or @localhost.localdomain is discarded while everything else is relayed through the specified host.

| improve this answer | |
  • 1
    This isn't the answer to the OP's question, but on a related note, here is what I did to throw away all outgoing mail on a temporary clone of a prod box: 1. Open /etc/postfix/main.cf 2. Add default_transport = discard:Outgoing email disabled on this node 3. Restart Postfix: service postfix restart * a reload may be sufficient – deoren Jul 18 '17 at 16:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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