- Shell 43.6%
- PHP 39%
- JavaScript 11.7%
- CSS 4.9%
- Makefile 0.4%
- Other 0.4%
| .forgejo/workflows | ||
| admin | ||
| dav | ||
| qpkg | ||
| roundcube | ||
| templates | ||
| tests | ||
| web | ||
| .gitignore | ||
| bvsapp.sh | ||
| CHANGELOG.md | ||
| mailctl | ||
| Makefile | ||
| proofreading-ledger.json | ||
| PROOFREADING.md | ||
| README.md | ||
| recipes.txt | ||
| schema.sql | ||
MailServerPro: a mail server
A mail server for QTS built from source by the App Builder, packed as the QTS package MailServerPro: Postfix for SMTP, Dovecot with Pigeonhole for IMAP, POP3, LMTP, Sieve and ManageSieve, Rspamd with
Valkey, ClamAV, Unbound and fail2ban against spam, viruses and password guessing, Roundcube for webmail, CalDAV and
CardDAV for calendars and contacts, Z-Push for Exchange ActiveSync, CryptPad as a web office (documents, sheets and
presentations in OnlyOffice's editors, rich text, kanban, whiteboard, diagrams, forms, a drive), and an admin panel.
Several domains live in one SQLite database. The recipes are in recipes.txt; the programs land in the app's prefix
/usr/app/mailserver, everything that changes (mail, queue, accounts, settings, certificates, keys, logs, backups) in a
data folder of its own.
Use it
In the IDE's terminal, as root on the NAS, with the Debian 12 builder environment (Examples: "Debian 12 builder (full)"):
make app build activate # make the App Builder app mailserver, build it, link /usr/app/mailserver to it
make start DATA=/share/CACHEDEV1_DATA/MailServerPro
Then open https://<NAS>:9581/admin/ from a computer on the local network: the first visit makes the administrator (a
mailbox of your first domain, with the password you set there; type an address at your own domain, since its domain
becomes the server's first mail domain). The Overview then lists what is left before mail works (a Host name of the
domain's own in place of the placeholder mail.example.org, a DKIM key for each domain), the addresses fail2ban locked
out, and the links to webmail and to calendars and contacts. The panel adds domains, mailboxes, aliases and DKIM keys
and lists the DNS records each domain needs, the ones mail needs first. TurboDNS's hosting template publishes the same
values for the records both name (MX, SPF, DMARC, autoconfig, autodiscover and the SRV records of 587, 465, 993 and 995)
when HOSTNAME is mail.<domain> (D317); with another HOSTNAME this list names that host, and the template still
names mail.<domain>. A domain's page says where its records go: to TurboDNS, through WebPortico's "Send DNS records
to TurboDNS" or TurboDNS's own panel, when TurboDNS on this NAS answers for the domain (App Center's list names it
and it answers the domain's NS question with authority, as WebPortico's DNS hand-off checks); else to the domain's DNS
provider (D333). Webmail is at https://<NAS>:9581/, calendars and contacts at https://<NAS>:9581/dav/, Rspamd's
own interface at /rspamd/.
The panel has the look of WebPortico's and TurboDNS's panels and runs no script (D222). Its status bar picks the language (English, Polish, German, French, Italian, Dutch, Swedish, Japanese, Traditional Chinese; until then the browser's) and the theme (dark, light or the system's), kept in a cookie of the browser. Deleting a domain or a mailbox asks for its name to be typed first.
The web office is at https://<HOSTNAME>:9582/, its sandbox at https://<HOSTNAME>:9583/ (D145): CryptPad needs
a second origin for the frames its editors run in, and another port is one. HOSTNAME (the admin panel's Settings)
must resolve to the NAS, and with the self-signed certificate a browser must accept it on both ports, once each, or
the editors stay blank. Office accounts are CryptPad's own, not the mailboxes (CryptPad encrypts in the browser with
keys from each user's password). Registration is closed after the install. The first administrator comes first: from a
computer on the local network, the admin panel's Office page makes a one-time CryptPad invitation; the account
registered through that link becomes CryptPad's administrator a few seconds later (the agent checks every 10 s), and
CryptPad's own Administration page then invites other people. The Office page opens registration for everyone, and
closes it again, and shows the storage the office takes. CryptPad 2026.5.1 has no setting that stops visitors
without an account from making documents: anyone who reaches port 9582 can still store a guest document (its
AppConfig.registeredOnlyTypes only hides buttons in the browser, and the server accepts a new document from anyone).
Keep 9582 and 9583 on the local network if that matters.
Roundcube's task bar has an Office link. An attachment is saved and imported into the office by hand; there is no
"open in the office" action (D146).
make test runs tests/e2e.sh on test ports in a temporary data folder. make qpkg builds the MailServerPro QTS package from the activated app when QDK is installed (Toolchains, an entry of kind qnap), with bvs qbuild;
QPKG_CERT_DIR=<folder> names a folder with the code-signing files certificate and private_key, and ca_certs
when it holds the chain, which lie next to qpkg.cfg only while qbuild runs; in CI, the workflow writes them from
the repository's Actions secrets QPKG_CERTIFICATE, QPKG_PRIVATE_KEY and QPKG_CA_CERTS (D370). The package leaves out what only a build reads (headers,
static archives) and strips the programs. Its service script links /usr/app/mailserver to its own app/ folder
and runs mailctl start with the data folder <install volume>/MailServerPro; a removal stops the server and keeps
that folder, and the mx-* accounts, for a later install.
An upgrade installs over the package and keeps its data folder (the path in etc/data-dir) and the mx-* accounts.
MailServerPro reads no other package's folder (D329).
Rspamd keeps greylisting, rate limits, Bayes and reputation in Valkey (D227), on a unix socket only, under Redis's
paths (etc/redis/redis.conf, lib/redis, run/redis/redis.sock, log/redis/redis.log) and with the setting
REDIS_MAXMEMORY.
The ports are the standard ones (25, 587, 465, 143, 993, 110, 995, 4190) and 9581 for the web side; QTS keeps 80
and 443. MTA-STS policies and Thunderbird's autoconfiguration are fetched by other machines from
https://mta-sts.<domain>/ and https://autoconfig.<domain>/ on port 443: forward that port to 9581 on the router,
or send those names to https://127.0.0.1:9581 with a WebPortico proxy site or a rule of QTS's reverse proxy (below).
WEB_ADDRESS (default all) chooses which addresses nginx's web ports (webmail and the admin panel on 9581, and
the office on 9582 and 9583 when it runs) listen on: all gives every IPv4 and IPv6 address, as before this
setting existed; a list of addresses separated by commas (mailctl set WEB_ADDRESS 10.100.200.12,127.0.0.1) gives
one listen line per address, an IPv6 address in brackets, and no wildcard line at all. Postfix and Dovecot have
their own address settings already (INET_INTERFACES, DOVECOT_LISTEN); WEB_ADDRESS is the same idea for
nginx. mailctl reload applies a change without restarting the other daemons; nginx itself gets a stop and a
start when the address list actually changed (a HUP alone would try to open the new sockets while the old ones are
still bound and fail), else just a HUP.
WEB_HTTP_PORT (default 9580) is a plain-HTTP listener that redirects every request to the same path on
WEB_HTTPS_PORT (D182). It exists for App Center's Open button: when QTS itself is reached over plain HTTP, App
Center builds the button's link on the package's Web_Port, over HTTP, and without a listener there it shows
QTS's own 403 or 404 instead of the admin panel. WEB_ADDRESS narrows it the same way as the other web ports.
The web office answers only at its own configured address, https://HOSTNAME:9582 (and the sandbox at :9583):
opened by the NAS's IP address, or by any other name, CryptPad's own sign-in fails silently, because the browser's
origin does not match the one CryptPad was told to expect. A request under any other Host on 9582 or 9583 (D183)
therefore gets a page naming the right address and the hosts-file line (or DNS record) that makes it resolve,
instead of reaching CryptPad; 127.0.0.1, ::1 and localhost are exempt, since an operator reaching the office
through an SSH tunnel or curl on the NAS itself gets CryptPad's own page there, as always. The admin panel's
Office page shows the exact address to open and this same caveat.
mailctl
mailctl -d DATA COMMAND (POSIX sh; on QTS it runs under the app's busybox):
| Command | What it does |
|---|---|
init |
the data folder, the service users (mx-*), the database from schema.sql, a self-signed certificate, the secrets |
render |
the configuration from templates/ and etc/mailserver.conf |
start, stop, restart, reload, status, check |
the daemons; check runs each daemon's own configuration test |
domain add/del/list/on/off |
domains |
mailbox add/passwd/quota/del/list/on/off/admin |
mailboxes; the password is read from stdin and hashed by Dovecot as ARGON2ID |
alias add/del/list, catchall DOMAIN [ADDRESS], forward EMAIL DEST keep|move |
aliases, the catch-all, forwarding with or without a kept copy |
public add FOLDER [RIGHTS] |
a public folder under Public/ with Dovecot ACL rights for every signed-in user |
dkim DOMAIN |
a DKIM key; Rspamd signs the domain's mail with it |
dns-records DOMAIN [--json] |
the records of the domain's zone the server owns (DKIM, MTA-STS and its host, TLS-RPT, the TLSA record when the mail host is in the domain); --json in the shape TurboDNS's local hand-off takes, which WebPortico's vhost dialog sends (D216; another package calls MailServerPro.sh dns-records DOMAIN) |
backup, backups, restore ARCHIVE EMAIL |
backups of every mailbox, and a mailbox restored into a folder Restored-<time> |
set KEY VALUE |
one setting (ports, HOSTNAME, TLS_SOURCE self/nas/import, CLAMAV, SEND_RATE, GREYLIST, DANE, MTA_STS_MODE, WEB_ADDRESS, ...) |
doveadm, postqueue, postsuper, sql |
the tools with this server's configuration |
agent |
the admin panel's root agent (start runs it) |
office status|open|close|invite |
the web office: whether it runs, registration (closed until opened), the number of administrators, storage; open/close let people register or not; invite makes the first administrator's one-time invitation |
OFFICE=off leaves the web office out; OFFICE_PORT, OFFICE_SANDBOX_PORT, OFFICE_WORKERS, OFFICE_UPLOAD_MB
and OFFICE_QUOTA_MB (the storage of each registered user, 1024 MB) are its other settings.
TLS_SOURCE=nas takes the NAS's own certificate (QTS keeps it in /etc/stunnel/stunnel.pem), for example the Let's
Encrypt certificate QTS renews. CLAMAV=on starts clamd, which holds the virus signatures in memory; it is off by
default.
With TLS_SOURCE=self, the default, the certificate is self-signed for HOSTNAME (D316). mailctl makes it at the
first start, and makes it again when HOSTNAME changes and 30 days before it ends (it lasts 825 days), at a start or
when the settings are saved. It keeps the same key each time. The TLSA record of DANE (3 1 1) is the hash of that
key, so its value stays the same; only its name, _25._tcp.<HOSTNAME>, follows the host. A browser that accepted the
old certificate asks again for the new one. A certificate signed by a certificate authority stays as it is under
self; TLS_SOURCE=import is the setting for such a certificate.
Behind a proxy on the NAS (D315). A WebPortico proxy site to https://127.0.0.1:9581 can put the webmail, the
MTA-STS policy and the autoconfiguration on port 443 under the domain's own names. Such a proxy connects from
127.0.0.1 and names the visitor in X-Forwarded-For. nginx takes the visitor's address from that header only on a
connection from 127.0.0.1 or ::1; a client anywhere else cannot name another address. PHP, the logs, fail2ban
and nginx's deny list therefore see the visitor: the first administrator and the office's first invitation are still
made from the local network only, and failed sign-ins get the visitor banned, not 127.0.0.1. A request whose
X-Forwarded-For, X-Real-IP or Forwarded header names a public address never counts as local, so a proxy that
nginx does not trust (one pointed at the NAS's network address) does not open the first-run setup either, as long
as it sends one of these headers. Its visitors' sign-ins are logged under the proxy's address, though: fail2ban never
bans 127.0.0.1 or ::1, and a ban of the NAS's network address would lock out every visitor of that proxy. Point a
proxy at 127.0.0.1. A proxy that sends none
of these headers makes every visitor look like the proxy. QTS's reverse proxy is Apache's mod_proxy, which adds
X-Forwarded-For on its own; give its rule the destination 127.0.0.1 (or localhost) and port 9581 over HTTPS.
Every jail's ban covers the whole server: Postfix, Dovecot and nginx refuse a banned address. The admin panel's
failed sign-ins (log/admin-auth.log, jail mailadmin) and CalDAV and CardDAV's (log/php-web.log, jail maildav)
count with the webmail's, Postfix's and Dovecot's. Up to 0.4.1 fail2ban read the admin panel's UTC times as the
NAS's local time (east of UTC it dropped the first lines it read after a start), and CalDAV and CardDAV's failed
sign-ins were not logged at all.
What is proven
tests/e2e.sh (root; a private mount namespace on Linux, --nas on QTS) starts the server on test ports in a
temporary data folder and checks, with the app's own curl, openssl and rspamc as the clients:
- mail: submission (587, STARTTLS, AUTH) and SMTPS (465), delivery through LMTP, two domains, an alias, a catch-all that does not take a mailbox's mail, forwarding with and without a kept copy, a user who may not send as another address, relaying refused on port 25 to a stranger, a message larger than a mailbox's quota refused at RCPT with 552, IMAP with STARTTLS on 143 and IMAPS, POP3 with STLS on 110 and POP3S, a Sieve rule and a vacation reply uploaded through ManageSieve (4190), IMAP IDLE seeing a delivery, a shared folder (IMAP SETACL) and a public folder with its ACL;
- with Rspamd (
tests/e2e-spam.sh;E2E_CLAMAV=onadds an EICAR attachment refused by ClamAV): its controller with and without the password, a DKIM signature of a key made bymailctl dkim, SPF and DMARC of example.net applied, the GTUBE message refused at the end of DATA, a marked message filed into Junk, Rspamd learning from a message copied into Junk, a mailbox's own send limit stopping it, a fail2ban ban that Dovecot and Postfix enforce, and the ban lifted; - with nginx and PHP (
tests/e2e-web.sh): a Roundcube sign-in and mail view, a CalDAV event and a CardDAV contact stored and read, a wrong DAV password refused,/.well-known/caldav, Thunderbird's autoconfig, Outlook's autodiscover and the MTA-STS policy, and the admin panel: the first administrator, a mailbox made there signing in to IMAP, the DNS records with the DKIM key and the TLSA record, a message to an unreachable address listed on the queue page, tried again and deleted there, every page, a backup through the agent and a mailbox restored from it; when the app has Z-Push, an ActiveSync OPTIONS request signed in through its IMAP, CalDAV and CardDAV backends, and a wrong password refused; - with Node.js and CryptPad (
tests/e2e-office.sh): CryptPad running, the office and its sandbox answering on their two ports over TLS,/api/confignaming the sandbox origin, the office's pages allowed to frame only the sandbox, OnlyOffice's editors and x2t (asapplication/wasm) served, a channel stored and read back through the websocket (tests/office-api.js), Roundcube's Office link, the admin panel's Office page (state, storage), registration closed by default and opened and closed again (CryptPad's/api/configsaying so after each restart), the first administrator's invitation and the invited account made CryptPad's administrator (the account written the way CryptPad records it), no worker of an earlier CryptPad left running, nothing written into the app's folder, and the office in the backup.
tests/office-browser.mjs ORIGIN [ADDRESS] runs on a machine with Node and Chromium (the build VM; Playwright from
the repository's ui/node_modules): a rich-text document written in a headless browser and read back in a second
one with nothing stored (with REGISTER=<the invitation link> first: the register page closed without it, the
invited account registered, and CryptPad listing it as its administrator), OnlyOffice's sheet, document and presentation editors drawing, CryptPad's own checkup page
with no error (the settings an instance's administrator chooses, such as terms of service, an admin e-mail or HSTS,
are printed as notes), and with OFFICE_DATA the document's text in none of the server's files.
Dovecot counts a client on one of the server's own addresses as secured, so tests/remote.sh HOST USER PASSWORD [BASE], run from another machine, checks that a password is refused without TLS.
tests/admin-ui.sh checks the admin panel without the app or a NAS, with PHP 8's CLI, Node, Chromium and Playwright's
playwright-core (CHROMIUM=, PLAYWRIGHT_CORE=): the nine catalogues against the code (tests/admin-i18n.php),
then every page served by PHP's built-in server over a scratch data folder, in English and Polish, dark and light,
at 1440, 1024 and 390 px: text past its box (also with long data strings), sideways scroll, contrast from the
pixels, the CSRF field of every form, no script, the cookies, the typed confirmations, a setting mailctl would refuse,
an administrator signed out once their rights are gone. 2026-10-02 in a cloud container: 252 views, 2787
checks, 0 failed. tests/dns-records.sh checks mailctl dns-records the same way, without the app (25 checks).
Results, 2026-09-26 and 27, app built as bundle for x86_64 in the pinned Debian 12 environment (the office's rows from 2026-09-27, with the recipes nodejs and cryptpad in the app, 49 recipes):
-
with the web office:
tests/e2e.sh112 passed, 0 failed, on the build VM and on .12 with--nas(the app copied to/share/CACHEDEV1_DATA/bvs-t54b);tests/office-browser.mjsfrom the build VM over HTTPS, against the VM's test server and against .12's: 0 failures, the text in none of the 32 (VM) and 29 (.12, the package) files underoffice/; -
Postfix and Dovecot alone, on the build VM (Ubuntu 24.04): 42 checks passed; on the test NAS .12 (QTS 6.1.0) with
--nas, the app copied to/share/CACHEDEV1_DATA/bvs-t54and linked at/usr/app/mailserver: 42 passed;tests/remote.shfrom the build VM against it: 6 passed (the password refused without TLS on 143 and 110, taken after STARTTLS and STLS, relaying refused for a stranger, mail for a mailbox taken from a stranger); -
the whole app (47 recipes), with the queue checks: 95 passed, 0 failed, on the build VM (in a data folder made by
mktemp -d, mode 0700) and on .12 with--nas(ClamAV off, the default); -
before the queue checks, on .12: with
E2E_CLAMAV=on(freshclam fetched the signatures, an EICAR attachment was refused with "clamav: virus found") 92 passed, 0 failed;tests/remote.shfrom the build VM: 6 passed, and the webmail, the admin panel and an ActiveSync OPTIONS request answered the build VM over the network.
The Postfix and Dovecot recipes, with their dependencies (16 recipes), also build for aarch64
(tools/recipe-test.sh --host aarch64-linux-gnu), their checks passing under qemu-user; the rest of the app has not
been built for aarch64.
The icon
qpkg/icons/ holds QDK's three icons (since D283): the package's icon, the same at 80 px and the grey one for a
stopped package, each a 256 px PNG under a .gif name. The picture is a stack of envelopes on blocks, recoloured to
violet from an isometric icon in an archive the owner supplied. The archive states no licence, and its file names
suggest artwork made for a hosting provider's pages; using it is the owner's decision of 2026-10-08. The earlier
packages had no icon of their own (QDK's default), so taking this one out again is one revert of that change.
A public example from Bucket & Code Server IDE, the QNAP QPKG that
turns a NAS into a build and publishing environment. This copy is generated by tools/publish-examples.sh
from the product's own example library; changes made here are not read back into it. The wizard's New Project
page builds one of these yourself, with your own name and account.