Postfix routing emails using LDAP or regexp with different smptd processes

If you want to redirect emails you can use the recipient_canonical_maps option.

This cleanup option is usually specified globally in

If you want to treat different domains with different filtering techniques, you can do this in instead:

# TCP/2525 : routing based on LDAP filter       inet  n       -       n       -       -       smtpd
        -o cleanup_service_name=cleanup-2525
        -o smtpd_banner=$myhostname

cleanup-2525 unix  n       -       n       -       0       cleanup
        -o recipient_canonical_maps=ldap:/etc/postfix/

# TCP/2526 : routing based on regexp filter       inet  n       -       n       -       -       smtpd
        -o cleanup_service_name=cleanup-2526
        -o smtpd_banner=$myhostname

cleanup-2526 unix  n       -       n       -       0       cleanup
        -o recipient_canonical_maps=regexp:/etc/postfix/

This means that Postfix will listen on port TCP/2525 for emails to, and apply an LDAP query to know where to route the email.

On port TCP/2526, emails for will be redirected based on regexp rules.

Examples or recipient_canonical_maps configurations:


server_host =
search_base = ou=company,ou=name,o=prd
bind_dn = cn=blah,ou=TechObjects,o=SYSTEM
bind_pw = MyVerySecurePassword

# %s = input --> this is the email address
query_filter = (&(mail=%s))
result_attribute = mailstop
result_format = %U@%s.%D


# Adresses starting with support go to server1
/^support(.*@)$/ ec${1}
# Adresses starting with business go to server2
/^business(.*@)$/ ms${1}