This helper manage mailbox users on Dovecot IMAP server by store settings in MariaDB.
Get the script as RAW move to sbin and make it executable.
curl -o /tmp/mailadmin.sh https://github.com/unblog/mailadmin/blob/main/mailadmin.sh
mv /tmp/mailadmin.sh /usr/local/sbin/mailadmin
chmod +x /usr/local/sbin/mailadminCreate account mailadmin with grant rights to database mailserver in MariaDB.
Note. Run
doveadm pw -s SHA512-CRYPT -p 'passwd123'for password-hash, check hash scheme using in dovecot.conf.
mysql -uroot
CREATE USER 'mailadmin'@'localhost' IDENTIFIED BY 'passwd123';
GRANT SELECT, INSERT, UPDATE, DELETE ON mailserver.* TO 'mailadmin'@'localhost';
FLUSH PRIVILEGES;Note: If a password is set for mysql root, you must also append the -p flag.
Change database namemailserverif they use a different one.
Create .mailadmin.cnf in your $HOME to store mailadmin secret.
[client]
user=mailadmin
password=passwd123Usage:
mailadmin add-domain domain.tld
mailadmin add-user email@domain.tld passwd123
mailadmin add-alias alias@domain.tld dest@domain.tld
mailadmin password email@domain.tld newpasswd
mailadmin delete-user email@domain.tld
mailadmin delete-alias alias@domain.tld [dest@domain.tld]
mailadmin delete-domain domain.tld [--force]
mailadmin listdelete-alias alias@domain.tld [dest@email.tld] – with a destination, only this single association is deleted; without a destination, all aliases with this source address are removed (including counter output).
delete-domain domain.tld [--force] – first checks if any users or aliases are still associated with the domain and, without --force, aborts with an error message instead of leaving orphaned entries in virtual_users/virtual_aliases. With --force, users and aliases of the domain are deleted first.