Postfix's virtual alias maps are commonly used to forward emails from one address to another. The basic syntax in /etc/postfix/virtual
is straightforward:
# Single recipient forwarding
original@domain.com recipient@example.com
This works perfectly for one-to-one forwarding scenarios. But what if you need to forward to multiple recipients?
Many administrators first try the intuitive approach of listing multiple entries:
# This WON'T work as expected
test@domain.com bob@me.com
test@domain.com bob2@me.com
Postfix will only use the last matching line, effectively ignoring all previous entries for the same original address.
The proper way to forward to multiple recipients is to list them on the same line, separated by commas:
# Correct multiple recipient syntax
test@domain.com bob@me.com,bob2@me.com
Some key points about this syntax:
- Use commas without spaces between addresses
- The entire recipient list goes on one line
- You can add as many recipients as needed
Here's a full example of a virtual alias file with multiple forwarding:
# /etc/postfix/virtual
# Single recipient
support@domain.com helpdesk@company.com
# Multiple recipients
alerts@domain.com admin1@ops.com,admin2@ops.com,admin3@ops.com
# Mixed forwarding
info@domain.com contact@support.com,archive@backup.com
After modifying the virtual file:
- Compile the virtual alias database:
postmap /etc/postfix/virtual
- Reload Postfix:
systemctl reload postfix
For more complex forwarding needs, consider these approaches:
Using Aliases File
For system accounts, you can use /etc/aliases
:
# /etc/aliases
developers: dev1@company.com, dev2@company.com, dev3@company.com
Then run newaliases
to apply changes.
Combining With Transport Maps
For advanced routing, combine virtual aliases with transport maps:
# /etc/postfix/transport
special.domain.com smtp:[mailserver.example.com]
When setting up email forwarding in Postfix, the virtual alias file is a powerful tool for simple forwarding cases. However, many administrators hit a wall when attempting to configure multiple forwarding destinations for a single email address.
Postfix processes the virtual file sequentially, and by default only the last matching entry takes effect. This explains why your second attempt failed:
test@domain.com bob@me.com
test@domain.com bob2@me.com
In this case, only emails to bob2@me.com would be delivered because it's the last matching rule.
The correct way to specify multiple recipients is by listing them on a single line, separated by commas:
test@domain.com bob@me.com,bob2@me.com
For more complex scenarios, you might want to consider these alternatives:
# Option 1: Using aliases file
test@domain.com team-alias
team-alias: bob@me.com,bob2@me.com,bob3@me.com
# Option 2: With recipient delimiter
test@domain.com bob@me.com,bob2@me.com,dev-team@company.com
After making changes to your virtual file, always remember to:
- Run
postmap /etc/postfix/virtual
- Restart Postfix:
systemctl restart postfix
- Test with:
sendmail -f sender@example.com test@domain.com
Here's a complete virtual file example for a development team setup:
# Main support channel
support@domain.com jane@me.com,bill@me.com,log@archive.com
# Dev team notifications
dev-alerts@domain.com team-lead@me.com,senior-dev@me.com,junior-dev@me.com
# Individual with backup
important@domain.com primary@me.com,backup@me.com