more content

This commit is contained in:
Christoph Haas 2024-12-07 16:34:59 +01:00
parent ec39ffed28
commit 1c028a051d
2 changed files with 57 additions and 2 deletions

View file

@ -45,3 +45,58 @@ If you get an error like “postmap: warning: connect to mysql server 127.0.0.1:
</Aside>
You should get 1 as a result. That means your first mapping is working. Feel free to try that with other domains after the `-q` in that line. You should not get a response.
## virtual\_mailbox\_maps
You will now define the _virtual\_mailbox\_maps_. It will map a recipients email address (left-hand side) to the location of the users mailbox on your hard disk (right-hand side). Postfix has a built-in transport service called “virtual” that can receive the email and store it into the recipients email directory. That service is pretty limited, so we will delegate that to Dovecot as it allows us better control.
Postfix will forward all emails to Dovecot for further delivery. But we need to make sure that the recipient actually exists before we do that. So Postfix needs to check whether an email address belongs to a valid mailbox. That simplifies things a bit because we just need the left-hand side of the mapping.
Similar to the above virtual\_domains mapping you need an SQL query that searches for an email address and returns “1” if it is found.
To accomplish that please create another configuration file at `/etc/postfix/mysql-virtual-mailbox-maps.cf`:
<pre>
user = mailserver
password = **x893dNj4stkHy1MKQq0USWBaX4ZZdq**
hosts = 127.0.0.1
dbname = mailserver
query = SELECT 1 FROM virtual_users WHERE email='%s'
</pre>
Again please use your actual password for the mailserver database user.
Tell Postfix that this mapping file is supposed to be used for the virtual\_mailbox\_maps mapping:
<pre class="wrap">
postconf virtual_mailbox_maps=mysql:/etc/postfix/mysql-virtual-mailbox-maps.cf
</pre>
Test if Postfix is happy with this mapping by asking it where the mailbox directory of our `john@example.org` user would be:
## virtual\_alias\_maps
The virtual\_alias\_maps mapping is used for forwarding emails from one email address to one or more others. In the database multiple targets are achieved by using multiple rows.
Create another “.cf” file at `/etc/postfix/mysql-virtual-alias-maps.cf`:
<pre>
user = mailserver
password = **x893dNj4stkHy1MKQq0USWBaX4ZZdq**
hosts = 127.0.0.1
dbname = mailserver
query = SELECT destination FROM virtual\_aliases WHERE source='%s'
</pre>
Make Postfix use this database mapping:
```
postconf virtual_alias_maps=mysql:/etc/postfix/mysql-virtual-alias-maps.cf
```
Test if the mapping file works as expected:
```
postmap -q jack@example.org mysql:/etc/postfix/mysql-virtual-alias-maps.cf
```
You should see the expected destination:
`john@example.org`

View file

@ -96,7 +96,7 @@ root@buster:~# mysql
Server version: 10.3.18-MariaDB-0+deb10u1 Debian 10
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
MariaDB \[(none)\]&gt;
MariaDB [(none)]>
```
Exit the SQL shell by typing “exit” or pressing CTRL-D.