Database Configuration

Madmail now supports GORM, which enables the use of various databases and automatic migration (Auto Migration).

Important: SQLite is used by default, but for high scalability, PostgreSQL is recommended.

SQLite (Default)

The simplest setup for quick deployment. The database file is stored at the specified path.

storage.imapsql local_mail {
    driver sqlite3
    dsn ./madmail.db
}

PostgreSQL

To use PostgreSQL, first create a database on your server (you can use the docker-compose.yml included in the project).

Example configuration in maddy.conf:

storage.imapsql local_mail {
    driver postgres
    dsn "host=localhost user=test password=test dbname=test port=5432 sslmode=disable"
}

Default credentials in Docker:

MySQL

To use MySQL, the DSN format is as follows:

storage.imapsql local_mail {
    dsn "user:password@tcp(localhost:3306)/dbname?charset=utf8mb4&parseTime=True&loc=Local"
}

In-memory caches vs on-disk state

For performance, the running server may keep a copy of credential rows (auth.pass_table) and per-user quota totals (storage.imapsql) in RAM. The authoritative data remains in the database files.

If you change those databases with the CLI (for example maddy creds, maddy accounts, or maddy imap-acct) while the daemon stays up, call the Admin API resource POST /admin/cache/reload once so the process re-reads the tables. Alternatively, restart the service.

Migration

The service automatically creates or updates required tables on first run. There is no need to run manual SQL commands to create quotas or contacts tables.