How to Redirect All Emails to a Single User in Postfix Using Catch-All Configuration


2 views

Many system administrators need to implement a catch-all email address that receives all messages sent to any nonexistent or unspecified address at their domain. While Postfix's alias system works well for individual addresses, configuring a wildcard redirect requires different techniques.

The most robust solution is using Postfix's virtual alias maps. First, edit your /etc/postfix/main.cf:

virtual_alias_domains = example.com
virtual_alias_maps = hash:/etc/postfix/virtual

Then create /etc/postfix/virtual with:

@example.com user@example.com

Compile the map and reload Postfix:

postmap /etc/postfix/virtual
systemctl reload postfix

For more advanced routing, transport maps can be effective. Add to main.cf:

transport_maps = hash:/etc/postfix/transport

Create /etc/postfix/transport:

example.com local:user

Then process and reload:

postmap /etc/postfix/transport
systemctl reload postfix

1. Security: Catch-all addresses attract spam. Consider combining with spam filtering.

2. Performance:

virtual_mailbox_domains = example.com
virtual_mailbox_maps = hash:/etc/postfix/vmailbox

This alternative approach may offer better performance for large domains.

Always verify with:

postmap -q @example.com hash:/etc/postfix/virtual

And test email delivery before deploying to production.


While /etc/aliases works perfectly for individual address mappings, attempting to use wildcards like *: user simply won't work because:

  1. Postfix aliases don't support wildcard syntax
  2. The newaliases command won't process asterisk characters
  3. This could create mail loops if not properly configured

1. Virtual Aliases with Regex Mapping

This is the most flexible approach. Edit your /etc/postfix/virtual_regexp:

/^.*@example\.com$/    user@example.com

Then update your Postfix configuration:

postconf -e "virtual_alias_maps = regexp:/etc/postfix/virtual_regexp, hash:/etc/postfix/virtual"
postmap /etc/postfix/virtual_regexp
systemctl reload postfix

2. Transport Maps for Advanced Routing

For more complex routing needs, use /etc/postfix/transport:

example.com    local:user@example.com

Configure Postfix to use transport maps:

postconf -e "transport_maps = hash:/etc/postfix/transport"
postmap /etc/postfix/transport
systemctl reload postfix
  • Test with postmap -q "test@example.com" regexp:/etc/postfix/virtual_regexp
  • Monitor your mail logs (tail -f /var/log/mail.log)
  • Consider security implications of catch-all addresses
  • For production systems, implement proper SPF/DKIM/DMARC records

If emails aren't being delivered as expected:

# Check mapping:
postmap -q "test@example.com" regexp:/etc/postfix/virtual_regexp

# Verify configuration:
postconf -n | grep virtual_alias_maps

# Test delivery:
sendmail -f test@external.com test@example.com < /dev/null