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:       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/       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

query_filter = (&(mail=%s))
result_attribute = mailstop
result_format = %U@%s.%D


/^support(.*@)$/ ec${1}
/^business(.*@)$/ ms${1}

Thanks for reading this post!

Did you find an issue in this article?

- click on the following Github link
- log into Github with your account
- click on the line number containing the error
- click on the "..." button
- choose "Reference in new issue"
- add a title and your comment
- click "Submit new issue"

Your feedback is much appreciated! πŸ€œπŸΌπŸ€›πŸΌ

You can also drop me a line below!