4 069
contributi
Riga 227: | Riga 227: | ||
3 | 2 | kerstin@foobar.org | kerstin@mycompany.com | 3 | 2 | kerstin@foobar.org | kerstin@mycompany.com | ||
</pre> | </pre> | ||
The black magic "email-to-email" mapping | |||
Before you define the virtual_alias_maps setting there is a small quirk you need to take care of. There is a special kind of forwarding: the "catchall" alias. Catchalls catch all emails for a domain if there is no specific user account. A catchall alias looks like "@example.com" and forwards email for the whole domain to one account. We have created the 'john@example.com' user and would like to forward all other email on the domain to 'kerstin@gmail.com'. So we would add a catchall alias like: | |||
source destination | |||
@example.com kerstin@gmail.com | |||
Now imagine what happens when Postfix receives an email for 'john@example.com'. Postfix will first check if there are any aliases in the virtual_alias_maps table. (It does not look at the virtual_mailbox_maps table at the moment.) It finds the catchall entry as above and since there is no more specific alias the catchall account matches and the email is redirected to 'kerstin@gmail.com'. This is probably not what you wanted. So you need to make the table rather look like this: | |||
email destination | |||
@example.com kerstin@gmail.com | |||
john@example.com john@example.com | |||
More specific aliases have precedence over general catchall aliases. Postfix will lookup all these mappings for each of: | |||
john@example.com (most specific) | |||
john (only works if "example.com" is the $myorigin domain) | |||
@example.com (catchall - least specific) | |||
Postfix will find an entry for 'john@example.com' first and sees that email should be "forwarded" to 'john@example.com' - the same email address. This trickery may sound weird but it is needed if you plan to use catchall accounts. So the virtual_alias_maps mapping must obey both the "view_aliases" view and this "john-to-himself" mapping. This is outlined in the virtual(5) man page in the TABLE SEARCH ORDER section. | |||
Create a ".cf" file /etc/postfix/mysql-email2email.cf for the latter mapping: | |||
user = mailuser | |||
password = mailuser2009 | |||
hosts = 127.0.0.1 | |||
dbname = mailserver | |||
query = SELECT email FROM virtual_users WHERE email='%s' | |||
Check that you get John's email address back when you ask Postfix if there are any aliases for him: | |||
$> postmap -q john@example.com mysql:/etc/postfix/mysql-email2email.cf | |||
The result should be the same address: | |||
john@example.com | |||
Now you need to tell Postfix that these two mappings should be searched by adding this line to your main.cf: | |||
$> postconf -e virtual_alias_maps=mysql:/etc/postfix/mysql-virtual-alias-maps.cf,mysql:/etc/postfix/mysql-email2email.cf | |||
The order of the two mappings is not important here. | |||
You did it! All mappings are set up and the database is generally ready to be filled with domains and users. Make sure that only 'root' and the 'postfix' user can read the ".cf" files - after all your database password is stored there: | |||
$> chgrp postfix /etc/postfix/mysql-*.cf | |||
$> chmod u=rw,g=r,o= /etc/postfix/mysql-*.cf |