Rewrite all email addresses using regex in postfix sender canonical file

To rewrite all email addresses to a specific address like "" in the Postfix sender_canonical file using regular expressions, you can follow these steps:

  1. Edit the sender_canonical File:

    Open the sender canonical mapping file. This file is usually located at /etc/postfix/sender_canonical. You can edit it using a text editor with superuser privileges:

    sudo nano /etc/postfix/sender_canonical
  2. Add Regular Expression Mapping:

    In the sender_canonical file, add regular expression mappings to rewrite email addresses. For example, to rewrite all email addresses to "," you can use the following format:


    This regular expression ^(.*)$ captures any email address and rewrites it to ""

  3. Update Postfix Configuration:

    Open your Postfix main configuration file, typically located at /etc/postfix/, using a text editor:

    sudo nano /etc/postfix/
  4. Configure sender_canonical_maps:

    Add or modify the sender_canonical_maps parameter in your file to specify the path to your sender_canonical file:

    sender_canonical_maps = regexp:/etc/postfix/sender_canonical

    This configuration tells Postfix to use the sender_canonical file with regular expressions for address rewriting.

  5. Reload Postfix Configuration:

    After making changes to the file, you should reload the Postfix configuration to apply the changes:

    sudo systemctl reload postfix

Now, Postfix will rewrite all email addresses using the regular expression specified in the sender_canonical file to "" when sending outbound emails. Make sure your regular expression in the sender_canonical file is crafted carefully to match the email addresses you want to rewrite accurately.


sender_canonical_classes = envelope_sender, header_sender
sender_canonical_maps =  regexp:/etc/postfix/sender_canonical_maps
smtp_header_checks = regexp:/etc/postfix/header_check

Rewrite envelope address from email originating from the server itself



Rewrite from address in SMTP relayed e-mail


/From:.*/ REPLACE From:

Copyright © 2013-present All rights reserved.