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 {
driver mysql
dsn "user:password@tcp(localhost:3306)/dbname?charset=utf8mb4&parseTime=True&loc=Local"
}
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.
پیکربندی پایگاه داده (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 {
driver mysql
dsn "user:password@tcp(localhost:3306)/dbname?charset=utf8mb4&parseTime=True&loc=Local"
}
مهاجرت (Migration)
سرویس به صورت خودکار جداول مورد نیاز را در اولین اجرا ایجاد یا بهروزرسانی میکند. نیازی به اجرای دستورات SQL
دستی برای ساخت جداول quotas یا contacts نیست.