Postfix - Virtual Aliasing (Email Redirect)

Card Puncher Data Processing


The main applications of virtual aliasing are:

  • To redirect mail for one address to one or more addresses.
  • To implement virtual alias domains where all addresses are aliased to addresses in other domains.

With virtual alias domains, each hosted address is aliased to:

Virtual alias domains are not to be confused with the virtual mailbox domains. With virtual mailbox domains, each recipient address can have its own mailbox. ie If you want to store the email locally without creating a linux user each time (ie not redirect them), you need to implements virtual MAILBOX

This process is implemented with the postfix virtual domain mail delivery agent.

The aliases table provides also a system-wide mechanism to redirect mail for local recipients. You can redirect to a command. where the E-mail message is passed on standard input. See postconf.5.html and postconf.5.html


Definition of the domains

With the postconf.5.html configuration, all recipient addresses are aliased to addresses in other domains.

A virtual alias domain can not be defined:

This feature is for Postfix > 2.0 (before the domain was in the virtual_alias_table)

virtual_alias_domains = ...other hosted domains...
# reload postfix /etc/postfix/
# optional only if you want to see the change immediately
postfix reload

Postfix is final destination for the specified list of virtual alias domains, that is, domains for which all addresses are aliased to addresses in other local or remote domains.

Virtual alias table

The virtual alias table is specified in the text file /etc/postfix/virtual that serves as input to the postmap command in order to output an indexed file (in dbm or db format) to speed up lookup.

virtual_alias_maps configuration

Just for info because this configuration is the default and should then not be changed

  • The virtual_alias_maps file defined the location of the alias text file hash is the database type (some systems use dbm). See the output from “postconf -m” for available database types.
virtual_alias_maps = hash:/etc/postfix/virtual
# reload postfix /etc/postfix/
postfix reload 

Alias definition (/etc/postfix/virtual)

Basically the format of this file is:

pattern address, address, 
# comment


  • pattern: A line has a pattern that defines the address that should be used if it matches an email. Each pattern is a regular expression that is applied to the entire address being looked up.
  • An address is a local address or to a remote address
  • multi-line text: A line that start with a space continue the previous line
  • Empty lines and whitespace-only lines are ignored,

You can see the whole file format definition at Postfix virtual alias table format

Alias definition Pattern

[email protected] address
[email protected] address, address, ...
addresses without @domain
user address, address, ...

When append_at_myorigin=yes, append “@myorigin” to addresses without “@domain”

@domain address
  • Redirect mail for other users in domain to address. This form has the lowest precedence. @domain is a wild-card and catch all addresses even if they does not exist.
@domain address, address, ...

The result becomes the same user in otherdomain. This works only for the first address in a multi-address lookup result.

addresses without “.domain”

When append_dot_mydomain=yes, append .mydomain


In this example, Mail for all other addresses in is rejected with the error message “User unknown”

[email protected] postmaster
[email protected]       joe
[email protected]      jane
[email protected]   [email protected]
# Uncomment entry below to implement a catch-all address
#         jim
...virtual aliases for more domains...

Rebuild the index

  • To rebuild the indexed file
# after changing the virtual file
postmap /etc/postfix/virtual

Reject code

unknown_virtual_alias_reject_code default to (550) is the Postfix SMTP server reply code when a recipient address matches virtual_alias_domains, and virtual_alias_maps specifies a list of lookup tables that does not match the recipient address.



echo -e "Subject: Virtual Aliasing with Postfix made easy  \n\n This is a redirected email \n" | sendmail [email protected]
  • Check the log
tail -f /var/log/maillog
Jun 15 13:14:50 vps748761 postfix/pickup[25222]: 00F401FBE8: uid=1002 from=<thenico>
Jun 15 13:14:50 vps748761 postfix/cleanup[25330]: 00F401FBE8: message-id=<[email protected]>
Jun 15 13:14:50 vps748761 opendkim[24477]: 00F401FBE8: DKIM-Signature field added (,
Jun 15 13:14:50 vps748761 postfix/qmgr[25223]: 00F401FBE8: from=<[email protected]>, size=388, nrcpt=1 (queue active)
Jun 15 13:14:50 vps748761 postfix/smtp[25333]: connect to[2a00:1450:400c:c00::1a]:25: Network is unreachable
Jun 15 13:14:50 vps748761 postfix/smtp[25333]: Untrusted TLS connection established to[]:25: TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)
Jun 15 13:14:51 vps748761 postfix/smtp[25333]: 00F401FBE8: to=<[email protected]>, orig_to=<[email protected]>,[]:25, delay=1.5, delays=0.08/0.02/0.57/0.81, dsn=2.0.0, status=sent (250 2.0.0 OK  1592219691 r14si13363181wrm.293 - gsmtp)
Jun 15 13:14:51 vps748761 postfix/qmgr[25223]: 00F401FBE8: removed

  • check your mail

Postfix Redirect Email Example


User unknown in virtual alias table

tail -f /var/log/maillog
Jun 15 12:51:28 vps748761 postfix/error[23201]: 506BB1FD27: to=<[email protected]>, relay=none, delay=0.07, delays=0.04/0.01/0/0.02, dsn=5.1.1, status=bounced (User unknown in virtual alias table)


Documentation / Reference

Recommended Pages
Card Puncher Data Processing
Email - Postfix

Postfix is a Mail Transport Agent (MTA), supporting LDAP, SMTP AUTH (SASL), TLS The postfix installation install also an alias to the sendmail command line. Doc...
Spf Dns Zone
Email - Sender Policy Framework (SPF)

SPF is a dns record that defines which server(s) may send an email. It describe the set of hosts which are designated outbound mailers for the domain. SPF is part of the mail authentication scheme with...
Postsrsd Spf Pass
Postfix - Sender Rewriting Scheme (SRS) installation

This page is the installation of postsrsd which implements Sender Rewriting Scheme (SRS) for Postfix Sender Rewriting Scheme (SRS) is mandatory in order to conform...

Share this page:
Follow us:
Task Runner