-   Linux - Server (
-   -   Postfix Virtual Wildcard Subdomains (

aaronvegh 12-20-2008 07:40 AM

Postfix Virtual Wildcard Subdomains
Hi there,
I have setup Postfix to use virtual domains with non-UNIX account users. What would you call this: virtual domains delivering to virtual accounts? Anyway, it's fine. I'd like to accept mail for all subdomains of the main domain, but I can't get it to work.

For example, I currently accept mail to I'd like to accept mail for any subdomain of the same, with the mail delivered to a catchall address. If it makes things any easier, all mail to the domain goes to just the one address.

The message I get when I try sending to is "relay access denied". The server receives the mail, but rejects it.

I've seen elsewhere some suggestion that the directive virtual_alias_maps should point to a regexp file, which I have tried in the current configuration, but it doesn't work.

Here's the files and all their relevant contents:


root@ubuntu:/etc/postfix# postconf -n
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
append_dot_mydomain = no
biff = no
config_directory = /etc/postfix
inet_interfaces = all
mailbox_command = procmail -a "$EXTENSION"
mailbox_size_limit = 0
mydestination = localhost.localdomain, localhost
myhostname = localhost
mynetworks = [::ffff:]/104 [::1]/128
myorigin = /etc/mailname
readme_directory = no
recipient_delimiter = +
relayhost =
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
smtpd_tls_cert_file = /etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file = /etc/ssl/private/ssl-cert-snakeoil.key
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtpd_use_tls = yes
virtual_alias_maps = hash:/etc/postfix/virtual, regexp:/etc/postfix/subdomain-catchall
virtual_gid_maps = static:1001
virtual_mailbox_base = /var/spool/vmail
virtual_mailbox_domains = /etc/postfix/vhosts.txt
virtual_mailbox_maps = hash:/etc/postfix/vmaps.txt
virtual_uid_maps = static:1001


root@ubuntu:/etc/postfix# cat virtual


root@ubuntu:/etc/postfix# cat subdomain-catchall


root@ubuntu:/etc/postfix# cat vhosts.txt


root@ubuntu:/etc/postfix# cat vmaps.txt

Thanks in advance for any help!

Berhanie 12-20-2008 12:34 PM

Your vhosts.txt should be

Also, the catchall address belongs in vmaps.txt, not virtual, unless the catchall address is the only address you have for the virtual mailbox domains.


Regarding the regexp question, you can have something like this:

virtual_mailbox_maps  = regexp:/path/to/vmaps.txt
And, in vmaps.txt

/^bob@amazingmac\.ca$/          somewhere/bob
/^alice@sub.amazingmac\.ca$/    somewhere/alice

/[@.]amazingmac\.ca$/          somewhere/bob

aaronvegh 12-20-2008 12:41 PM

Thanks so much for responding!

I added the "" to vhosts.txt, and still the same response: "relay access denied".


Also, the catchall address belongs in vmaps.txt, not virtual, unless the catchall address is the only address you have for the virtual mailbox domains.
The catchall address IS the only address.

Berhanie 12-20-2008 01:03 PM


The catchall address IS the only address.
Ok, so you can just make virtual regexp table, unless you want a different catchall for each subdomain.
Also, please take a look at my first post again, since I made some additions to it.

Debugging suggestions:

1. make sure you can send mail to the parent domain first.
2. make sure a catchall works for the parent using a hash table for virtual.
3. keeping a hash format for virtual, add a catchall for a specific subdomain and test it.
4. now use regexp for virtual.

aaronvegh 12-20-2008 08:42 PM

Hi Berhanie,
Thanks again for going above and beyond for me here. Everything is working now! In particular, your advice about how to use the regexp was spot-on; this is clearly an area where I'm weak.

You're the man!


Berhanie 12-21-2008 08:44 AM

You're welcome, Aaron.

johnjreeve 07-14-2011 05:52 PM

I found this thread particularly useful for setting up virtual wildcard subdomains on my server. So I wrote up everything I did and put it into a blog post. Hope this helps:

All times are GMT -5. The time now is 07:45 AM.