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:
- Username:
test
- Password:
test
- Database:
test
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 the quotas or contacts tables.
Configuración de la base de datos
Madmail admite GORM, lo que permite
usar distintos motores de base de datos y migración automática.
Importante: SQLite es el valor por defecto, pero para mayor escalabilidad
se recomienda PostgreSQL.
SQLite (predeterminado)
La opción más simple para despliegues rápidos. El archivo de base de datos se guarda en la ruta indicada.
storage.imapsql local_mail {
driver sqlite3
dsn ./madmail.db
}
PostgreSQL
Para usar PostgreSQL, cree primero una base en su servidor (puede usar el
docker-compose.yml incluido en el proyecto).
Ejemplo en maddy.conf:
storage.imapsql local_mail {
driver postgres
dsn "host=localhost user=test password=test dbname=test port=5432 sslmode=disable"
}
Credenciales por defecto en Docker:
- Usuario:
test
- Contraseña:
test
- Base de datos:
test
MySQL
El formato DSN para MySQL es el siguiente:
storage.imapsql local_mail {
dsn "user:password@tcp(localhost:3306)/dbname?charset=utf8mb4&parseTime=True&loc=Local"
}
Cachés en memoria frente al estado en disco
Por rendimiento, el servidor en ejecución puede mantener en RAM una copia de las filas de credenciales (auth.pass_table) y los totales de cuota por usuario (storage.imapsql). Los datos autoritativos siguen estando en los archivos de la base.
Si modifica esas bases con la CLI (por ejemplo maddy creds, maddy accounts o maddy imap-acct) mientras el demonio sigue en marcha, invoque una vez el recurso de la API de administración POST /admin/cache/reload para que el proceso vuelva a leer las tablas. También puede reiniciar el servicio.
Migración
El servicio crea o actualiza las tablas necesarias en el primer arranque. No hace falta ejecutar SQL
manual para crear las tablas quotas o contacts.
پیکربندی پایگاه داده (Database Configuration)
سرویس Madmail اکنون از GORM پشتیبانی میکند که
امکان استفاده از پایگاه دادههای مختلف و مهاجرت خودکار (Auto Migration) را فراهم میسازد.
نکته مهم: به طور پیشفرض از SQLite استفاده میشود، اما برای مقیاسپذیری بالا، استفاده از
PostgreSQL توصیه میگردد.
SQLite (پیشفرض)
سادهترین حالت برای راهاندازی سریع. فایل پایگاه داده در مسیر مشخص شده ذخیره میشود.
storage.imapsql local_mail {
driver sqlite3
dsn ./madmail.db
}
PostgreSQL
برای استفاده از PostgreSQL، ابتدا یک دیتابیس در سرور خود ایجاد کنید (میتوانید از
docker-compose.yml موجود در پروژه استفاده کنید).
نمونه تنظیمات در فایل maddy.conf:
storage.imapsql local_mail {
driver postgres
dsn "host=localhost user=test password=test dbname=test port=5432 sslmode=disable"
}
اطلاعات پیشفرض در Docker:
- نام کاربری:
test
- رمز عبور:
test
- نام دیتابیس:
test
MySQL
برای استفاده از MySQL، فرمت DSN به صورت زیر است:
storage.imapsql local_mail {
dsn "user:password@tcp(localhost:3306)/dbname?charset=utf8mb4&parseTime=True&loc=Local"
}
کش حافظه در برابر دیتابیس روی دیسک
برای سرعت، سرور در حال اجرا ممکن است ردیفهای اعتبارنامه (auth.pass_table) و مجموع سهمیه هر کاربر (storage.imapsql) را در RAM نگه دارد. منبع حقیقی همچنان فایلهای دیتابیس است.
اگر با CLI (مثلاً maddy creds، maddy accounts یا maddy imap-acct) در حالی که سرویس روشن است دیتابیس را عوض کردید، یک بار Admin API را با POST /admin/cache/reload صدا بزنید تا فرآیند دوباره جداول را بخواند؛ یا سرویس را ریاستارت کنید.
مهاجرت (Migration)
سرویس به صورت خودکار جداول مورد نیاز را در اولین اجرا ایجاد یا بهروزرسانی میکند. نیازی به اجرای دستورات SQL
دستی برای ساخت جداول quotas یا contacts نیست.