05PostfixMariaDB - amagerard/Mail GitHub Wiki
Redhat/Mail
1- Network | 2- Postfix | 3- Dovecot | 4- Postfixadmin | 5- PostfixMariaDB | 6- DovecotMariaDB |
---|---|---|---|---|---|
7- RelaySmtp | 8- Troubleshoot | 9- Selinux | 10- GnomeShell | 11- Backup |
5. Postfix-MariaDB.
5.1 Part Three (2/3).
Configure Postfix to use MySQL/MARIADB database.
5.2 Installation.
dnf install -y postfix-mysql
5.3 Configuration.
vi /etc/postfix/main.cf
Put the following at the end of the file.
virtual_mailbox_domains = proxy:mysql:/etc/postfix/sql/mysql_virtual_domains_maps.cf
virtual_mailbox_maps =
proxy:mysql:/etc/postfix/sql/mysql_virtual_mailbox_maps.cf,
proxy:mysql:/etc/postfix/sql/mysql_virtual_alias_domain_mailbox_maps.cf
virtual_alias_maps =
proxy:mysql:/etc/postfix/sql/mysql_virtual_alias_maps.cf,
proxy:mysql:/etc/postfix/sql/mysql_virtual_alias_domain_maps.cf,
proxy:mysql:/etc/postfix/sql/mysql_virtual_alias_domain_catchall_maps.cf
virtual_transport = lmtp:unix:private/dovecot-lmtp
Create the “sql” directory.
mkdir /etc/postfix/sql/
Create the following files.
vi /etc/postfix/sql/mysql_virtual_domains_maps.cf
user = postfixadmin
password = D51mAB49!
hosts = localhost
dbname = postfixadmin
query = SELECT domain FROM domain WHERE domain='%s' AND active = '1'
#query = SELECT domain FROM domain WHERE domain='%s'
#optional query to use when relaying for backup MX
#query = SELECT domain FROM domain WHERE domain='%s' AND backupmx = '0' AND active = '1'
#expansion_limit = 100
vi /etc/postfix/sql/mysql_virtual_mailbox_maps.cf
user = postfixadmin
password = D51mAB49!
hosts = localhost
dbname = postfixadmin
query = SELECT maildir FROM mailbox WHERE username='%s' AND active = '1'
#expansion_limit = 100
vi /etc/postfix/sql/mysql_virtual_alias_domain_mailbox_maps.cf
user = postfixadmin
password = D51mAB49!
hosts = localhost
dbname = postfixadmin
query = SELECT maildir FROM mailbox,alias_domain WHERE alias_domain.alias_domain = '%d' and mailbox.username = CONCAT('%u', '@', alias_domain.target_domain) AND mailbox.active = 1 AND alias_domain.active='1'
vi /etc/postfix/sql/mysql_virtual_alias_maps.cf
user = postfixadmin
password = D51mAB49!
hosts = localhost
dbname = postfixadmin
query = SELECT goto FROM alias WHERE address='%s' AND active = '1'
#expansion_limit = 100
vi /etc/postfix/sql/mysql_virtual_alias_domain_maps.cf
user = postfixadmin
password = D51mAB49!
hosts = localhost
dbname = postfixadmin
query = SELECT goto FROM alias,alias_domain WHERE alias_domain.alias_domain = '%d' and alias.address = CONCAT('%u', '@', alias_domain.target_domain) AND alias.active = 1 AND alias_domain.active='1'
vi /etc/postfix/sql/mysql_virtual_alias_domain_catchall_maps.cf
# handles catch-all settings of target-domain
user = postfixadmin
password = D51mAB49!
hosts = localhost
dbname = postfixadmin
query = SELECT goto FROM alias,alias_domain WHERE alias_domain.alias_domain = '%d' and alias.address = CONCAT('@', alias_domain.target_domain) AND alias.active = 1 AND alias_domain.active='1'
Allow read-only for root and postfix.
chmod 0640 /etc/postfix/sql/*
setfacl -R -m u:postfix:rx /etc/postfix/sql/
Use only virtual accounts and not local.
vi /etc/postfix/main.cf
Modify the line mydestination.
# See also below, section "REJECTING MAIL FOR UNKNOWN LOCAL USERS".
#
mydestination = $myhostname, localhost.$mydomain, localhost
And add at the end of the file.
vi /etc/postfix/main.cf
virtual_mailbox_base = /var/vmail
virtual_minimum_uid = 2000
virtual_uid_maps = static:2000
virtual_gid_maps = static:2000
systemctl restart postfix
5.4 Create a vmail user without home.
By default user UIDs and group GIDs are limited to 999.
vi /etc/login.defs
Modify the lines.
SYS_UID_MAX 2001
SYS_GID_MAX 2001
adduser vmail --system --uid 2000 --user-group --no-create-home
cat /etc/passwd| grep vmail
vmail:x:2000:2000::/home/vmail:/bin/bash
mkdir /var/vmail/
chown -R vmail:vmail /var/vmail/