* Open `updateLDAPValues_061_to_070.py`, config below parameters in file head:
```
# Part of file: updateLDAPValues_061_to_070.py
uri = 'ldap://127.0.0.1:389'
basedn = 'o=domains,dc=iredmail,dc=org'
bind_dn = 'cn=vmailadmin,dc=iredmail,dc=org'
bind_pw = 'passwd'
```
You can find required LDAP credential in iRedAdmin config file or `iRedMail.tips`
file under your iRedMail installation directory. Using either
`cn=Manager,dc=xx,dc=xx` or `cn=vmailadmin,dc=xx,dc=xx` as bind dn is ok.
* Execute this script, it will add missing values for mail accounts:
```
# python updateLDAPValues_061_to_070.py
```
## MySQL backend only
### Improve backup mx support
* Edit `/etc/postfix/mysql_domain_alias_maps.cf`, change `query =` to below new setting:
```
# Part of file: /etc/postfix/mysql_domain_alias_maps.cf
query = SELECT alias.goto FROM alias,alias_domain,domain WHERE alias_domain.alias_domain='%d' AND alias.address=CONCAT('%u', '@', alias_domain.target_domain) AND alias_domain.target_domain=domain.domain AND alias.active=1 AND alias_domain.active=1 AND domain.backupmx=0
query = SELECT CONCAT(mailbox.storagenode, '/', mailbox.maildir) FROM mailbox,domain WHERE mailbox.username='%s' AND mailbox.active='1' AND mailbox.enabledeliver='1' AND domain.domain = mailbox.domain AND domain.active='1'
```
__WARNING__: If you don't have column `storagenode` present in table
`vmail.mailbox`, please add it with below SQL command:
```
$ mysql -uroot -p
mysql> USE vmail;
mysql> ALTER TABLE mailbox ADD COLUMN storagenode VARCHAR(255) NOT NULL DEFAULT '';
query = SELECT alias.goto FROM alias,domain WHERE alias.address='%s' AND alias.domain='%d' AND alias.domain=domain.domain AND alias.active=1 AND domain.backupmx=0 AND domain.active=1
query = SELECT mailbox.transport FROM mailbox,domain WHERE mailbox.username='%s' AND mailbox.domain='%d' AND mailbox.domain=domain.domain AND mailbox.active=1 AND mailbox.enabledeliver=1 AND domain.backupmx=0 AND domain.active=1 AND mailbox.transport<>''
query = SELECT mailbox.username FROM mailbox,domain WHERE mailbox.username='%s' AND mailbox.domain='%d' AND mailbox.domain=domain.domain AND mailbox.enablesmtp=1 AND mailbox.active=1 AND domain.backupmx=0 AND domain.active=1
query = SELECT recipient_bcc_user.bcc_address FROM recipient_bcc_user,domain WHERE recipient_bcc_user.username='%s' AND recipient_bcc_user.domain='%d' AND recipient_bcc_user.domain=domain.domain AND domain.backupmx=0 AND domain.active=1 AND recipient_bcc_user.active=1
```
* Edit postfix config file `mysql_sender_bcc_maps_user.cf`, change `query =` to
below new setting:
```
# Part of file: mysql_sender_bcc_maps_user.cf
query = SELECT sender_bcc_user.bcc_address FROM sender_bcc_user,domain WHERE sender_bcc_user.username='%s' AND sender_bcc_user.domain='%d' AND sender_bcc_user.domain=domain.domain AND domain.backupmx=0 AND domain.active=1 AND sender_bcc_user.active=1
```
* Edit dovecot config file `/etc/dovecot-mysql.conf` (RHEL/CentOS) or
`/etc/dovecot/dovecot-mysql.conf` (Debian/Ubuntu/openSUSE) or
`/usr/local/etc/dovecot-mysql.conf` (FreeBSD):
```
# Part of file: dovecot-mysql.conf
user_query = SELECT CONCAT(mailbox.storagebasedirectory, '/', mailbox.storagenode, '/', mailbox.maildir) AS home, CONCAT('*:bytes=', mailbox.quota*1048576) AS quota_rule FROM mailbox,domain WHERE mailbox.username='%u' AND mailbox.domain='%d' AND mailbox.enable%Ls%Lc=1 AND mailbox.domain=domain.domain AND mailbox.active=1 AND domain.backupmx=0 AND domain.active=1
```
It will now check domain status, so if this domain is disabled, all users and
aliases will be disabled too.
Restart postfix and dovecot services to make it work.
### Make catch-all account work as expected
To make catch-all account work as expected, we need two more SQL lookup files:
*`/etc/postfix/catchall_maps.cf`: Catch-all support for exist domains.
* /etc/postfix/domain_alias_catchall_maps.cf: Catch-all support for alias domains.
Now edit postfix config file `/etc/postfix/main.cf` (Linux) or
`/usr/local/etc/postfix/main.cf` (FreeBSD), append these two lookup files in
Now create these two new files (Note: You can create them based on exist mysql
lookup files, copy "`user`, `password`, `hosts`, `port`, `dbname`" to new files):
*`/etc/postfix/catchall_maps.cf`:
```
# File: catchall_maps.cf
user = vmail
password = PASSWORD_OF_VMAIL
hosts = 127.0.0.1
port = 3306
dbname = vmail
query = SELECT alias.goto FROM alias,domain WHERE alias.address='%d' AND alias.address=domain.domain AND alias.active=1 AND domain.active=1 AND domain.backupmx=0
```
*`/etc/postfix/domain_alias_catchall_maps.cf`:
```
# File: domain_alias_catchall_maps.cf
user = vmail
password = PASSWORD_OF_VMAIL
hosts = 127.0.0.1
port = 3306
dbname = vmail
query = SELECT alias.goto FROM alias,alias_domain,domain WHERE alias_domain.alias_domain='%d' AND alias.address=alias_domain.target_domain AND alias_domain.target_domain=domain.domain AND alias.active=1 AND alias_domain.active=1
```
Restart postfix to make it work.
### Update SQL structure of `vmail` database
* Add some more columns:
```
$ mysql -uroot -p
USE vmail;
-- enablesmtpsecured: Used for SMTP over SSL support in Postfix + Dovecot.
ALTER TABLE mailbox ADD COLUMN enablesmtpsecured TINYINT(1) NOT NULL DEFAULT '1';
-- name: Used to store common name of admin and alias account.
ALTER TABLE admin ADD COLUMN name VARCHAR(255) DEFAULT '' COLLATE utf8_general_ci;
ALTER TABLE alias ADD COLUMN name VARCHAR(255) DEFAULT '' COLLATE utf8_general_ci;
-- passwordlastchange: Store date of password last change.
ALTER TABLE admin ADD COLUMN passwordlastchange DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00';
ALTER TABLE mailbox ADD COLUMN passwordlastchange DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00';
-- local_part: Used for PostfixAdmin compatible.
ALTER TABLE mailbox ADD COLUMN local_part VARCHAR(255) NOT NULL DEFAULT '';
-- defaultuseraliases: Assign new user to these aliases
ALTER TABLE domain ADD COLUMN defaultuseraliases TEXT NOT NULL DEFAULT '';