A feature-rich CLI tool for managing Dovecot mail users with beautiful colored output and comprehensive error handling.
- π¨ Beautiful colored logging with indicators
- π§ Build-time configuration via
config.json - π Cross-platform support - builds for 20+ OS/architecture combinations
- π Secure password handling with interactive prompts and masking
- β Input validation for email addresses and user existence
- π‘οΈ Safety features with confirmation prompts for destructive operations
- π¦ Single binary with no runtime dependencies (except Dovecot)
- π― Production-ready with comprehensive error handling
- Go 1.16+ (for building)
- Dovecot with
doveadmcommand - Root/sudo privileges (for running)
jq(for building with Makefile)- Linux/Unix-like system with systemctl
git clone https://github.com/jelius-sama/mail-mgmt.git
cd mail-mgmtEdit config.json to match your system:
{
"Version": "1.0.0",
"PasswdFile": "/etc/dovecot/passwd",
"VmailBaseDir": "/var/vmail",
"DovecotService": "dovecot",
"VmailUser": "vmail",
"VmailGroup": "mail",
"HashScheme": "SHA512-CRYPT",
"DoveadmCmd": "doveadm"
}# Build for your current system
make host_default
# Build for all supported platforms
make all
# Clean build artifacts
make cleanThe binary will be in bin/mail-mgmt (or bin/mail-mgmt-<os>-<arch> for cross-compiled builds).
sudo cp bin/mail-mgmt /usr/local/bin/
sudo chmod +x /usr/local/bin/mail-mgmtInteractive (recommended):
sudo mail-mgmt create -user john@example.comNon-interactive:
sudo mail-mgmt create -user john@example.com -password "SecurePassword123"What it does:
- Validates email format
- Checks if user already exists
- Prompts for password (with confirmation if interactive)
- Generates SHA512-CRYPT hash
- Adds user to
/etc/dovecot/passwd - Creates Maildir structure (
/var/vmail/domain/user/Maildir/{cur,new,tmp}) - Sets proper ownership and permissions
- Reloads Dovecot service
With confirmation:
sudo mail-mgmt delete -user john@example.comSkip confirmation:
sudo mail-mgmt delete -user john@example.com -yesWhat it does:
- Validates email format
- Checks if user exists
- Confirms deletion (unless
-yesflag is used) - Removes user from
/etc/dovecot/passwd - Deletes entire Maildir directory
- Reloads Dovecot service
Interactive (recommended):
sudo mail-mgmt change-password -user john@example.com
# or use the alias:
sudo mail-mgmt passwd -user john@example.comNon-interactive:
sudo mail-mgmt change-password -user john@example.com \
-old-password "OldPassword" \
-new-password "NewPassword123"What it does:
- Validates email format
- Checks if user exists
- Verifies old password against stored hash
- Prompts for new password (with confirmation if interactive)
- Generates new hash
- Updates
/etc/dovecot/passwd - Reloads Dovecot service
# Show help
sudo mail-mgmt help
# Show version and build configuration
sudo mail-mgmt versionSuccess:
βΉ INFO Creating mail user: john@example.com
β Enter password for john@example.com:
β Confirm password:
β Generating password hash...
β Adding user to /etc/dovecot/passwd...
β Creating Maildir structure...
β Reloading Dovecot...
β SUCCESS User created successfully: john@example.com
Error:
β ERROR User already exists: john@example.com
Warning:
β WARNING This will permanently delete user john@example.com and all their emails
The build process uses ldflags to inject configuration from config.json at compile time. This means:
- No runtime configuration files needed - everything is embedded in the binary
- Zero-dependency deployment - just copy the binary
| Option | Default | Description |
|---|---|---|
Version |
1.0.0 |
Application version |
PasswdFile |
/etc/dovecot/passwd |
Path to Dovecot passwd file |
VmailBaseDir |
/var/vmail |
Base directory for mail storage |
DovecotService |
dovecot |
Systemd service name |
VmailUser |
vmail |
System user for mail files |
VmailGroup |
mail |
System group for mail files |
HashScheme |
SHA512-CRYPT |
Password hashing scheme |
DoveadmCmd |
doveadm |
Path to doveadm command |
The Makefile supports building for multiple platforms:
# Build for your host platform
make host_default
# Build for specific platform
make linux_arm64
# Build for all platforms
make crossSupported platforms:
- Linux: amd64, arm, arm64, ppc64, ppc64le, mips, mipsle, mips64, mips64le, s390x
- macOS: amd64 (Intel), arm64 (Apple Silicon)
- FreeBSD: amd64, 386
- OpenBSD: amd64, 386, arm64
- NetBSD: amd64, 386, arm
- DragonFly BSD: amd64
- Solaris: amd64
- Plan 9: 386, amd64
.
βββ main.go # Main application code
βββ config.json # Build-time configuration
βββ Makefile # Build automation
βββ README.md # This file
- Add a list command:
case "list":
handleList()- Add export/import for bulk operations:
sudo mail-mgmt export > users.csv
sudo mail-mgmt import users.csv- Add quota management:
sudo mail-mgmt quota -user john@example.com -size 5G- Add email alias management:
sudo mail-mgmt alias add -from info@example.com -to john@example.comThe tool needs root privileges to modify system files and reload Dovecot.
sudo mail-mgmt <command>Install Dovecot or update DoveadmCmd in config.json to the full path.
# Find doveadm location
which doveadmCheck if Dovecot service is running:
sudo systemctl status dovecotInstall jq for JSON parsing in Makefile:
# Ubuntu/Debian
sudo apt-get install jq
# macOS
brew install jq
# CentOS/RHEL
sudo yum install jqContributions are welcome! Please feel free to submit a Pull Request.
Jelius Basumatary
- Built with Go
- Designed for Dovecot mail server
- Inspired by the need for better mail user management tools