0

I have a working Postfix config with some local mailboxes, some local aliases and a handful of purely virtual alias domains. Because I find it tedious to add all to virtual_alias_domains I'm asking: How to define them by simply using them in virtual_alias_maps?

Example:

### /etc/postfix/main.cf
myhostname = mx.example.com
virtual_alias_domains =
    foo.example
    bar.example
virtual_alias_maps = hash:/etc/postfix/virtual

### /etc/postfix/virtual
single-user@foo.example single-user@example.com
@bar.example            whole-domain@example.com

# this one is missing in virtual_alias_domains and won't work
@baz.example            me@example.com

When adding new entries like baz.example I will probably forget to list them in virtual_alias_domains. This also breaks the common rule of Don't repeat yourself.

How to get rid of virtual_alias_domains or "compile it dynamically"?

http://www.postfix.org/postconf.5.html#virtual_alias_domains says the default of virtual_alias_domains is $virtual_alias_maps:

The default value is $virtual_alias_maps so that you can keep all information about virtual alias domains in one place.

But this seems not to work for me.

Jan 31 00:09:25 HOSTNAME postfix/smtpd[5064]: NOQUEUE: reject: RCPT from FROM_HOSTNAME[185.XXX.XXX.XXX]: 454 4.7.1 <FROM_ADDRESS>:
  Relay access denied; from=<FROM_ADDRESS> to=<TO_ADDRESS> proto=ESMTP helo=<FROM_HOSTNAME>

(anonymized log, inserted newline for readability) My actual configuration:

# postconf -n | egrep ^virtual_
virtual_alias_maps = hash:/etc/postfix/virtual 

# postconf | egrep ^virtual_alias
virtual_alias_address_length_limit = 1000
virtual_alias_domains = $virtual_alias_maps
virtual_alias_expansion_limit = 1000
virtual_alias_maps = hash:/etc/postfix/virtual
virtual_alias_recursion_limit = 1000

Unfortunately I don't know to dump the configuration of virtual_alias_domains after variable expansion.

Daniel Böhmer
  • 271
  • 2
  • 13
  • `virtual_alias_domains` should not be set at all. This part of your configuration is correct. The problem is going to be elsewhere. – Michael Hampton Jan 31 '19 at 01:55
  • @MichaelHampton: Sounds good. Do you have any hints how to debug this? – Daniel Böhmer Jan 31 '19 at 09:46
  • You need to look at your `virtual_mailbox_` settings. – Michael Hampton Jan 31 '19 at 13:16
  • I had a look at the difference between `virtual_alias_maps` and `virtual_mailbox_maps`. I am not sure which is more appropriate in my case. But I tried changing to `virtual_mailbox_maps` and it makes no differences: still relay access denied. – Daniel Böhmer Feb 01 '19 at 00:03
  • I just tried `virtual_mailbox_maps` with `virtual_mailbox_domains` for completeness' sake and it just doesn't work. So I stepped back to `virtual_alias_maps` but I still need to list all the domains. – Daniel Böhmer Feb 01 '19 at 00:15
  • I don't know what's going on; neither of your last two comments makes any sense to me. Please post your entire Postfix configuration so we can see what might be going on. – Michael Hampton Feb 01 '19 at 03:08

1 Answers1

1

I ran into this same problem. This answer is correct but I wasn't quite understanding what it meant.

To use a single file for both virtual_alias_maps and virtual_alias_domains, you need to separately include each domain that you are forwarding for, without an @. To keep Postfix happy, both a key and value are required, but for these domain entries the value can be anything you want, since Postfix is only checking for the existence of the key (the domain).

Example /etc/postfix/virtual:

# These are the virtual aliases:
single-user@foo.example single-user@example.com
@bar.example            whole-domain@example.com
@baz.example            me@example.com

# Repeat the bare domains:
foo.example             LITERALLY_ANYTHING
bar.example             LITERALLY_ANYTHING
baz.example             LITERALLY_ANYTHING

You could conceivably keep a file of just the alias mappings, and run it through a script to extract the domains and create the combined output file, but at that point you could also pass the domains to postconf -e, or put the domain entries in a separate file and run postmap on it, then tell virtual_alias_domains to use that file. For me, adding the extra domain entries manually is fine, but it is nice to have it all in one place.

Brad Nabholz
  • 126
  • 1
  • Not perfect, but far better than my original state. I have a lot of aliases configured—so I put the list of domains at the top of the hashmap file. – Daniel Böhmer May 05 '23 at 08:57