TABLE_MYSQL(5)
π TABLE_MYSQL β bestie edition π
okay so this is table_mysql(5), a File Formats Manual page, and it's literally the glow-up guide for how smtpd MySQL / MariaDB tables are formatted. yes we're doing databases today, grab a boba π§
β¨ NAME β¨
table_mysql β format description for smtpd MySQL or MariaDB tables
πΈ DESCRIPTION πΈ
This manual page documents the file format of MySQL or MariaDB tables used by the smtpd(8) mail daemon. π
The format described here applies to tables as defined in smtpd.conf(5).
π¦ MYSQL TABLE π¦
A mysql table allows the storing of usernames, passwords, aliases, and domains in a format that is shareable across various machines that support mysql(1). like, it's giving portable. it's giving main character.
The table is used by smtpd(8) when authenticating a user, when user information such as user-id and/or home directory is required for a delivery, when a domain lookup may be required, and/or when looking for an alias.
A MySQL table consists of one or more mysql(1) databases with one or more tables. layers on layers, no cap.
π If the table is used for authentication, the password should be encrypted using thecrypt(3)function. Such passwords can be generated using theencrypt(1)utility orsmtpctl(8)encryptcommand. do NOT be out here storing plaintext, that's not the vibe, that's a crime against good taste π
π MYSQL TABLE CONFIG FILE π
The following configuration options are available:
hosthostname β This is the host running MySQL or MariaDB. For example:
host db.example.com
usernameusername β The username required to talk to the MySQL or MariaDB database. For example:
username maildba
passwordpassword β The password required to talk to the MySQL or MariaDB database. For example:
password OpenSMTPDRules!
databasedatabse β The name of the MySQL or MariaDB database. For example:
databse opensmtpdb
π okay bestie the keyword is literally spelled databse in the example and we are NOT fixing it, that's just how the page says it, we respect the lore. copy it exactly or your config will simply not eat.
query_aliasSQL statement β This is used to provide a query to look up aliases. The question mark is replaced with the appropriate data. For alias it is the left hand side of the SMTP address. This expects oneVARCHARto be returned with the user name the alias resolves to.query_credentialsSQL statement β This is used to provide a query for looking up user credentials. The question mark is replaced with the appropriate data. For credentials it is the left hand side of the SMTP address. The query expects that there are twoVARCHARSreturned, one with a user name and one with a password incrypt(3)format.query_domainSQL statement β This is used to provide a query for looking up a domain. The question mark is replaced with the appropriate data. For the domain it would be the right hand side of the SMTP address. This expects oneVARCHARto be returned with a matching domain name.query_mailaddrmapSQL statement β This is used to provide a query to look up senders. The question mark is replaced with the appropriate data. This expects oneVARCHARto be returned with the address the sender is allowed to send mails from.
A generic SQL statement would be something like:
query_ SELECT value FROM table WHERE key=?;
π EXAMPLES π
β GENERIC EXAMPLE β
Example based on the OpenSMTPD FAQ: Building a Mail Server. The filtering part is excluded in this example.
The configuration below is for a medium-size mail server which handles multiple domains with multiple virtual users and is based on several assumptions. One is that a single system user named vmail is used for all virtual users. This user needs to be created:
# useradd -g =uid -c "Virtual Mail" -d /var/vmail -s /sbin/nologin vmail
# mkdir /var/vmail
# chown vmail:vmail /var/vmail
π MySQL schema
CREATE TABLE domains (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
domain VARCHAR(255) NOT NULL DEFAULT ''
);
CREATE TABLE virtuals (
id INT AUTO_INCREMENT PRIMARY KEY,
email VARCHAR(255) NOT NULL DEFAULT '',
destination VARCHAR(255) NOT NULL DEFAULT ''
);
CREATE TABLE credentials (
id INT AUTO_INCREMENT PRIMARY KEY,
email VARCHAR(255) NOT NULL DEFAULT '',
password VARCHAR(255) NOT NULL DEFAULT ''
);
INSERT INTO domains VALUES (1, "example.com");
INSERT INTO domains VALUES (2, "example.net");
INSERT INTO domains VALUES (3, "example.org");
INSERT INTO virtuals VALUES (1, "abuse@example.com", "bob@example.com");
INSERT INTO virtuals VALUES (2, "postmaster@example.com", "bob@example.com");
INSERT INTO virtuals VALUES (3, "webmaster@example.com", "bob@example.com");
INSERT INTO virtuals VALUES (4, "bob@example.com", "vmail");
INSERT INTO virtuals VALUES (5, "abuse@example.net", "alice@example.net");
INSERT INTO virtuals VALUES (6, "postmaster@example.net", "alice@example.net");
INSERT INTO virtuals VALUES (7, "webmaster@example.net", "alice@example.net");
INSERT INTO virtuals VALUES (8, "alice@example.net", "vmail");
INSERT INTO credentials VALUES (1, "bob@example.com", "$2b$08$ANGFKBL.BnDLL0bUl7I6aumTCLRJSQluSQLuueWRG.xceworWrUIu");
INSERT INTO credentials VALUES (2, "alice@example.net", "$2b$08$AkHdB37kaj2NEoTcISHSYOCEBA5vyW1RcD8H1HG.XX0P/G1KIYwii");
π /etc/mail/mysql.conf
host db.example.com
username maildba
password OpenSMTPDRules!
database opensmtpdb
query_alias SELECT destination FROM virtuals WHERE email=?;
query_credentials SELECT email, password FROM credentials WHERE email=?;
query_domain SELECT domain FROM domains WHERE domain=?;
π /etc/mail/smtpd.conf
table domains mysql:/etc/mail/mysql.conf
table virtuals mysql:/etc/mail/mysql.conf
table credentials mysql:/etc/mail/mysql.conf
listen on egress port 25 tls pki mail.example.com
listen on egress port 587 tls-require pki mail.example.com auth <credentials>
accept from any for domain <domains> virtual <virtuals> deliver to mbox
π MOVING FROM POSTFIX (& POSTFIXADMIN) π
π /etc/mail/mysql.conf
host db.example.com
username postfix
password PostfixOutOpenSMTPDin
database postfix
query_alias SELECT destination FROM alias WHERE email=?;
query_credentials SELECT username, password FROM mailbox WHERE username=?;
query_domain SELECT domain FROM domain WHERE domain=?;
The rest of the config remains the same. slay, that's it, that's the migration π«Ά
π FILES π
/etc/mail/mysql.confβ Defaulttable-mysql(8)configuration file.
π₯ TODO π₯
Documenting the following query options:
query_netaddr
query_userinfo
query_source
query_mailaddr
query_addrname
π yes bestie these are literally undocumented, we're all just out here living our truth. not me manifesting a future version where this section is empty β¨
π SEE ALSO π
smtpd.conf(5), smtpctl(8), smtpd(8), encrypt(1), crypt(3)
okay that's the whole page, you ate that, go configure your mail server πβ¨
this was the Debian build, dated July 4, 2016 β sending u all the love, xoxo, your local Unix bestie ππ¦
π¦ where this page comes from
- alpine 3.24: opensmtpd-table-mysql-doc 1.2.1-r0 Β· ISC
- arch rolling: opensmtpd-table-mysql 1.2.1-1 Β· ISC
- debian trixie: opensmtpd-table-mysql 1.2.1-1+b1 Β· ISC
- nixos 26.05: opensmtpd-table-mysql 1.2.1
- nixpkgs unstable: opensmtpd-table-mysql 1.2.1
- ubuntu questing: opensmtpd-table-mysql 1.2.1-1ubuntu1
- ubuntu resolute: opensmtpd-table-mysql 1.2.1-1ubuntu2 Β· ISC
- ubuntu stonking: opensmtpd-table-mysql 1.2.1-2 Β· ISC
- Copyright (c) 2013 Eric Faurot <eric@openbsd.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms