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