Skip to content

Latest commit

 

History

44 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

A helper script to manage Dovecot mailbox users in MySQL from CLI

This helper manage mailbox users on Dovecot IMAP server by store settings in MariaDB.

Install

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/mailadmin

Create 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 name mailserver if they use a different one.

Create .mailadmin.cnf in your $HOME to store mailadmin secret.

[client]
user=mailadmin
password=passwd123
Usage:
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 list

under the hood

delete-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.

About

A helper script to manage Dovecot mailbox users in MySQL from CLI.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages