To rewrite sender addresses in postfix using canonical_maps
, you need to configure postfix to use a canonical map file.
Create the canonical map file:
First, create a file that will contain your canonical mapping. For example, let’s create a file named /etc/postfix/canonical
.
# vi /etc/postfix/canonical
Add your address rewrites in the file. The format is:
original_address rewritten_address
For example:
olduser@example.com newuser@example.com
Postmap the canonical file:
After editing the file, you need to create a hash database file that postfix can use:
# postmap /etc/postfix/canonical
Edit your main postfix configuration file, main.cf, to specify the use of the canonical map. Add or modify the following lines:
# vi /etc/postfix/main.cf
Add these lines if they are not already present:
canonical_maps = hash:/etc/postfix/canonical
sender_canonical_maps = hash:/etc/postfix/canonical
Reload Postfix:
After making these changes, reload postfix to apply the new configuration:
# systemctl reload postfix
Verify the configuration:
Send a test email to ensure that the sender address is being rewritten as expected. Check the postfix logs for any errors or confirmation that the address has been rewritten.