My postfix / dovecot installation is already configured to accept mail for me@A.com. However, since my Apache is running multiple virtual domains with domain name mapping. I would like to create a info@B.net email that forwards to me@A.com. Is there a standard way to handle this?


Ok, I did as fkraiem said but this is what happened:

/usr/sbin/postconf: warning: /etc/postfix/main.cf, line 44: overriding earlier entry: virtual_alias_maps=hash:/etc/postfix/virtual_aliases

Below the main.cf file

smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = A.com
alias_maps = hash:/etc/aliases, hash:/var/spool/postfix/plesk/aliases
alias_database = hash:/etc/aliases
mydestination = A.com, localdomain, localhost, localhost.localdomain, localhost
relayhost = 
mailbox_command = procmail -a "$EXTENSION"
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = all
virtual_alias_domains = B.net
virtual_alias_maps = hash:/etc/postfix/virtual_aliases
virtual_mailbox_domains = $virtual_mailbox_maps, hash:/var/spool/postfix/plesk/virtual_domains
virtual_alias_maps = $virtual_maps, hash:/var/spool/postfix/plesk/virtual
virtual_mailbox_maps = , hash:/var/spool/postfix/plesk/vmailbox
transport_maps = regexp:/etc/postfix/transport
smtpd_tls_security_level = may
smtp_tls_security_level = may
smtp_use_tls = no
smtpd_timeout = 3600s
smtpd_proxy_timeout = 3600s
disable_vrfy_command = yes
smtpd_sender_restrictions = check_sender_access hash:/var/spool/postfix/plesk/blacklists, permit_sasl_authenticated
smtpd_client_restrictions = permit_mynetworks, permit_sasl_authenticated
smtp_send_xforward_command = yes
smtpd_authorized_xforward_hosts = [::1]/128
smtpd_sasl_auth_enable = yes
smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination
virtual_mailbox_base = /var/qmail/mailnames
virtual_uid_maps = static:30
virtual_gid_maps = static:31
smtpd_milters = , inet:
sender_dependent_default_transport_maps = hash:/var/spool/postfix/plesk/sdd_transport_maps
virtual_transport = plesk_virtual
plesk_virtual_destination_recipient_limit = 1
mailman_destination_recipient_limit = 1
virtual_mailbox_limit = 0
smtp-1000_destination_rate_delay = 12s
smtp-1000_destination_concurrency_limit = 1
smtp-1000_destination_recipient_limit = 2
smtp-1000_initial_destination_concurrency = 1
myorigin = /etc/mailname
mynetworks = IP/32 [::1]/128 [::2]/128
home_mailbox = Maildir/
smtpd_sasl_local_domain = 
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
smtpd_tls_auth_only = no
smtp_tls_note_starttls_offer = yes
smtpd_tls_CAfile = /etc/ssl/certs/cacert.pem
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
tls_random_source = dev:/dev/urandom

And this error I got back after sending an email:

5.1.0 - Unknown address error 550-'5.1.1 <info@B.net>: Recipient address rejected: User unknown in virtual alias table'
  • Yes, what you want is called virtual aliases, try to Google it. – fkraiem Jan 22 '16 at 0:53
  • Virtual aliases in postfix? – El Dude Jan 22 '16 at 1:02
  • 1
    In Postfix, yes. – fkraiem Jan 22 '16 at 1:03
  • Actually, maybe not. How should mail sent to me@B.net or to info@A.com be handled? Should those addresses be rejected as nonexistent, or should all mail sent to me@ (resp. info@) be handled in the same way? – fkraiem Jan 22 '16 at 1:45
  • Apache serves both domains, A.com and B.net. However, info@B.net shall be forwarded to me@A.com , or (you are right) could be forwarded to my real, private email address from a large provider. That eventually does not matter... – El Dude Jan 22 '16 at 18:25

You need to use a mechanism in Posftix called virtual aliases if

  • your system handles mail for domain.com (i.e., a MX record points to it); and
  • you want to redirect all mail sent to @domain.com addresses to other, "real" addresses (no matter whether they're also hosted on your system or somewhere else such as on Gmail).

It's quite easy to do, there are mostly three steps.

  1. Add the domain domain.com to the virtual_alias_domains directive in your Postfix configuration, and remove it from the mydestination directive if it is there.
  2. Create the virtual aliases file for example at /etc/postfix/virtual_aliases. In it, put lines like this

    foo@domain.com real@address.com

    Mail sent to any address not explicitly mapped in the file will be rejected, but you can also add a catch-all address like this

    @domain.com catchall@address.com

    Then do sudo postmap /etc/postfix/virtual_aliases to create the hashed version of the file, which Postfix will actually use.

  3. Add hash:/etc/postfix/virtual_aliases to the virtual_alias_maps directive in your Postfix configuration.

And after reloading Postfix it should do what you want.

  • When I do this ALL mail goes to the catch-all address, not just mail sent to non-existent accounts. This seems to be a very common problem. – Forkbeard Mar 18 '16 at 10:36
  • @CaptainForkbeard It does not do that here. Do you see anything in mail.log or mail.err? – fkraiem Mar 18 '16 at 10:49
  • Nothing out of the ordinary and it is normal behaviour. From postfix.org/VIRTUAL_README.html#virtual_alias: "...shows how one would implement a catch-all virtual alias that receives mail for every example.com address not listed in the virtual alias file." So if you're using a database for storing e-mail addresses this will not work (unless you list all addresses in the virtual_aliases file as well). – Forkbeard Mar 31 '16 at 8:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.