If sender ‘firstname.lastname@example.org’ sends an email, his email address should change to ‘email@example.com’ and at the receiver’s mailbox, the from address must be shown as ‘firstname.lastname@example.org’. This article provides a step by step procedure rewriting sender email address using Postfix.
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
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 email@example.com firstname.lastname@example.org email@example.com admin firstname.lastname@example.org email@example.com
The above example, rewrites sender address firstname.lastname@example.org to email@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.