
If sender ‘test@example.com’ sends an email, his email address should change to ‘admin@example.com’ and at the receiver’s mailbox, the from address must be shown as ‘admin@example.com’. This article provides a step by step procedure rewriting sender email address using Postfix.
Topic
-
If sender ‘A’ sends an email to any recipient/email address, sender address of ‘A’ should change to ‘B’ before postfix sends the email to the recipient.
-
Postfix Rewrite sender email address
-
Postfix modify sender email address
-
Postfix change sender email address
apt
- Linux
Resolution
We can use postfix ADDRESS_REWRITING feature to achieve this goal. Refer to the following upstream documentation for more information.
Postfix Rewrite Sender Email Address Configuration
- Add the following entry in /etc/postfix/main.cf file.
sender_canonical_maps = hash:/etc/postfix/canonical_sender_address
- Add all your requirement to /etc/postfix/canonical_sender_address file. And the following is the sample entry.
$ cat /etc/postfix/canonical_sender
test@example.com admin@example.com
test1@example.com admin
test3@example.com test4@example.com
-
The above example, rewrites sender address test@example.com to admin@example.com.
-
Then execute the following command to build the HASH database for postfix.
# postmap hash:/etc/postfix/canonical_sender
- Now restart postfix service to validate the configuration.