13

I thought I understood "Alias domains" as that it's simply an alias for another domain! So when I set up a mailbox like "[email protected]", and add "alias.com" as a domain alias for "main.com" the address "[email protected]" would also work... But no!

So, I've added these domains:

  • main.com
  • alias.com

I've created this mailbox:

Then I mapped these alias domains:

  • alias.com => main.com

And then when I send a mail to [email protected] I receive this error:

Recipient address rejected: User unknown in virtual mailbox table (state 13).

I don't want to create an alias for every domain, as I have a few. I also don't want to use a wildcard (like info@*) because there are also other domains that aren't aliases of main.com

So... what are these exactly?

1
  • I expected the same and still don't understand why that's not the case.
    – Josh M.
    Jan 26, 2015 at 21:12

4 Answers 4

5

The explanation is in the documentation: http://www.postfix.org/VIRTUAL_README.html#virtual_alias

You want "alias mailboxes" aka virtual_mailbox_alias and virtual_mailbox_maps but talk about "alias domains": http://www.postfix.org/ADDRESS_CLASS_README.html#virtual_alias_class

2
  • 4
    I can't seem to make sense of the docs - how do you have domain1.com alias any mailbox to <mailbox>@domain2.com?
    – Josh M.
    Jan 26, 2015 at 21:16
  • 2
    @JoshM. You can use a hash table in virtual_alias_maps with an entry of the form @domain1.com @domain2.com. See my answer for details.
    – Sam Hanes
    Dec 29, 2016 at 12:09
18

Adding alias.com to virtual_alias_domains is the correct first step, but that just tells Postfix that you want to use that domain for aliases. It doesn't say what the aliases should be. For that, you need to use a virtual alias map.

First, add something like this to main.cf:

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

Adding virtual_alias_maps gets you a file (/etc/postfix/virtual) that's used as a virtual alias map. But what do you put in that file? According to the virtual(5) manpage:

The input format for the postmap(1) command is as follows:

  pattern address, address, ...

When pattern matches a mail address, replace it by the corresponding address.

and

With lookups from indexed files such as DB or DBM, or from networked tables such as NIS, LDAP or SQL, each user@domain query produces a sequence of query patterns as described below. Each query pattern is sent to each specified lookup table before trying the next query pattern, until a match is found.

...

@domain address, address, ...

Redirect mail for other users in domain to address.

and

The lookup result is subject to address rewriting: When the result has the form @otherdomain, the result becomes the same user in otherdomain. This works only for the first address in a multi-address lookup result.

Therefore, putting this in /etc/postfix/virtual will achieve the full-domain alias that you want:

# map any <user>@alias.com to the matching <user>@main.com
@alias.com     @main.com

Then, since that file is a hash table, you need to run postmap (explanation, manpage):

postmap /etc/postfix/virtual

You can find more information about virtual domains in the Postfix Virtual Domain HOWTO and about aliases in the Postfix Address Rewriting HOWTO.

3
  • So, the PostfixAdmin interface have a bug, because the interface (edit.php?table=aliasdomain) fail to say to user that no alias in fact will occur when flagging it as enabled. Dec 27, 2016 at 13:26
  • 2
    I wouldn't say it's a bug, exactly, since it does in fact configure a virtual alias domain. Rather, I suspect that PostfixAdmin expects you to know what Postfix virtual alias domains are, and that you also need to add actual aliases in order to make them do anything. It would probably be better if it told you that, though.
    – Sam Hanes
    Dec 29, 2016 at 12:07
  • @SamHanes For those using SQL with PostFix does this extra mapping go into the Alias table? And With PostfixAdmin how does one add in the correct alias? There doesn't seem to be an interface in PostFixadmin to put in that type of alias. Oct 16, 2020 at 18:56
1

@Josh M.

I have no idea whether this is the right way and/or good practice but I'm using something like this:

virtual_alias_maps = regexp:/etc/postfix/domain_rewriting pgsql:/etc/postfix/pgsql/     virtual_alias_maps.cf

$ cat /etc/postfix/domain_rewriting 
/^(.*)@domain1.com$/     ${1}@domain2.com
1
  • 2
    While not exactly incorrect (it'll do what you expect), using a regex table is less efficient than using a hash table with the @domain1.com @domain2.com syntax that I detailed in my answer.
    – Sam Hanes
    Dec 29, 2016 at 12:04
1

This is my short version of @sam-hanes ' answer (that worked for me)

In your virtual_alias_maps add :

@from.domain <tab> @to.domain

In the command line do :

 postmap /path/to/yourvirtualalismapsfile

In your main.cf file add :

virtual_alias_domains : from.domain

virtual_alias_domains tells postfix that all mailbox addresses that are in the form of [email protected] are all aliases.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .