Mail clients

Kantoor serves IMAP, POP3 and SMTP submission itself. All three are off by default: with none of the variables below set, no mail port is opened.

Outgoing mail from a mail client goes through Kantoor's SMTP submission service, which hands every message to Karta; the message is acknowledged only after Karta accepted it. See SMTP submission.

Automatic set-up

If your operator has published the discovery records (DNS records), clients can fill the settings in themselves from your address:

  • Thunderbird, Evolution, KMail, K-9: type your address; the server settings are found. Enter an app password when asked.
  • iPhone, iPad, Mac: open Settings, App passwords and choose Download an Apple profile, then install it (Settings, "Profile Downloaded" on iOS; System Settings, Profiles on macOS). It sets up mail, calendar and contacts with your address as the user name and asks for an app password; it contains no password and is unsigned, so the device says "Not Signed". Create the app password first, with the imap, smtp and dav scopes.
  • Outlook: Kantoor answers Outlook's Autodiscover request with IMAP and SMTP settings. Whether Outlook uses it for an account that is not on Exchange depends on the version (and Outlook on the web and some mobile apps never do), so it has not been proven with a real Outlook. If it does not find the server, add the account by hand with the values in the next section (choose IMAP).

The values for your own account

Settings, Mail apps shows the settings for your mailboxes with the host names and ports this server actually serves, each with a copy button and a "copy all settings" block. Use that page instead of the mail.example.com examples below when you set up a client; it also links to the app-password page and the Apple profile.

Connect Evolution, Thunderbird, DAVx5, iOS and macOS

First make an app password at Settings, App passwords with the scopes the client needs (imap, smtp and dav; pop3 only for POP3). Every client below uses the same login: your sign-in email address (or any mailbox address you may open) and the app password. The examples use mail.example.com; use your own host name. Give the client the host, or https://mail.example.com/dav/, and it finds the rest (/.well-known/caldav and /.well-known/carddav answer 301 to /dav/; PROPFIND on / and on /dav/ answers current-user-principal, calendar-home-set and addressbook-home-set).

ClientMailCalendar, tasks and contacts
GNOME EvolutionNew account, Collection Account: e-mail address, user name = your address, Look up. Or Mail Account by hand: IMAP mail.example.com, 993, SSL/TLS, password authentication; sending: SMTP mail.example.com, 465, SSL/TLSCollection Account finds the calendars, the task list and the address book; with Calendar, Task List or Contacts as a separate account choose type CalDAV / CardDAV, URL https://mail.example.com/dav/, user = your address
ThunderbirdAccount Settings, Add Mail Account: name, address, app password. Autoconfiguration finds IMAP 993 SSL/TLS and SMTP 465 SSL/TLS. By hand: the same values, authentication Normal passwordCalendar: New Calendar, On the Network, CalDAV, location https://mail.example.com/dav/, then your address and app password; Thunderbird lists every calendar and task list. Contacts: Address Book, Add CardDAV Address Book, user name = your address, server https://mail.example.com/dav/
DAVx5 (Android)use K-9 or FairEmail for mail with the IMAP and SMTP values aboveLogin with URL and user name: base URL https://mail.example.com/dav/, user name = your address, password = the app password. DAVx5 shows each calendar, task list and address book to switch on
iPhone, iPadSettings, App passwords, Download an Apple profile, install it, enter the app password. By hand: Mail, Accounts, Add Account, Other: IMAP mail.example.com 993 SSL, SMTP mail.example.com 465 SSLin the profile; by hand: Calendar, Accounts, Add Account, Other, Add CalDAV Account, server mail.example.com, user name, password; likewise Add CardDAV Account.
macOS (Mail, Calendar, Contacts)the same profile (System Settings, Profiles), or Internet Accounts, Add Other Account, Mail AccountInternet Accounts, Add Other Account, CalDAV account / CardDAV account, account type Manual, user name, password, server https://mail.example.com/dav/

Notes:

  • Tasks (VTODO) are kept in the Tasks list, which is what a task app should be pointed at. The Calendar collection takes events and tasks.
  • A shared calendar appears in the grantee's calendar home as shared-<id>; a subscribed (external) calendar is read-only over CalDAV.
  • The default collections are named Calendar, Tasks and Contacts.
  • If a client says the certificate is wrong, the host name you typed is not the one on the certificate; Kantoor never asks a client to trust a certificate.

Which clients were actually exercised, and how (as of 1.0.0, against the live server):

Client or libraryWhat was runResult
GNOME Evolution's discovery code (libedataserver, the Look up of a Collection Account)the real code, with the host and with /.well-known/caldavfound the calendars, the task list, the address book and the user's addresses
vdirsyncer 0.21.0discover and two-way sync of every calendar, the task list and the address book against the live server; a local event, task and card uploaded, a server edit pulled down, local deletes propagatedworked
isync/mbsync 1.4.4 (Alpine container)pull of INBOX, Sent, Drafts and sub-folders over IMAPS, a locally written message pushed backworked
Python imaplib, poplib, smtplib, requestsevery IMAP, POP3, SMTP and DAV operation of the 1.0 inventoryworked
Thunderbird, DAVx5not run. The requests each is documented to make (RFC 6764 .well-known, OPTIONS, PROPFIND for current-user-principal, the home sets, calendar-user-address-set, supported-calendar-component-set, getctag, sync-token, then sync-collection and multiget) were replayed by script, and every answer was checkedall 33 checks passed
iOS, macOS, Outlook, K-9not run, not replayed; the steps above follow their documentationunverified

Before a client can connect

  1. Enable the protocols on the server and choose their ports (see Installing Kantoor).
  2. Configure a TLS certificate, or put the ports behind a TCP proxy that terminates TLS and sends the PROXY protocol.
  3. Create an app password for each device in Settings, App passwords with the imap, pop3 or smtp scope. The password is shown once; it cannot be read back. It can be given an expiry date and revoked at any time.

The login is the user's sign-in email address, or the address of any mailbox that user may open. The password is the app password. There is no user+tag or user*mailbox syntax.

Failed logins are rate limited per IP and login. A throttled login is answered NO [UNAVAILABLE] over IMAP and -ERR [SYS/TEMP] over POP3.

Client settings

The values below assume the public host name mail.example.com. Use the ports you enabled.

SettingIMAPPOP3
Servermail.example.commail.example.com
Implicit TLS port993995
STARTTLS/STLS port143110
User nameyour sign-in email or a mailbox addresssame
Passwordan app password with the imap scopean app password with the pop3 scope
SecuritySSL/TLS (993) or STARTTLS (143)SSL/TLS (995) or STLS (110)

Inside the container the listeners use unprivileged ports: 1143 (IMAP plain) and 1993 (IMAPS) by default, 1110 (POP3 plain) and 1995 (POP3S). Map them to the standard ports outside the container, or change them with KANTOOR_IMAP_PORT, KANTOOR_IMAPS_PORT, KANTOOR_POP3_PORT and KANTOOR_POP3S_PORT.

Plain-text authentication is refused unless the connection is already encrypted and KANTOOR_IMAP_ALLOW_PLAINTEXT_AUTH or KANTOOR_POP3_ALLOW_PLAINTEXT_AUTH is set. Leave those off.

SMTP submission

When both ports are published, Settings, Mail apps shows both with the same user name and app password. Thunderbird and Outlook discovery include both. The default Apple profile retains the primary SMTP option; Apple profile with STARTTLS selects port 587 without adding a duplicate mail account.

SettingValue
Servermail.example.com
Port and security465 with SSL/TLS, or 587 with STARTTLS
Authenticationnormal password (PLAIN or LOGIN)
User nameyour sign-in email or a mailbox address (the same as for IMAP)
Passwordan app password with the smtp scope

Evolution, Thunderbird, iOS Mail and K-9 accept these values. The server is KANTOOR_SMTP_ENABLED=true; inside the container it listens on 1587 (STARTTLS) and 1465 (implicit TLS) unless KANTOOR_SMTP_PORT and KANTOOR_SMTPS_PORT say otherwise. Behind a TLS-terminating TCP proxy only the 465 route is offered (see the deploy notes).

Rules a client meets:

  • Login is required before MAIL FROM, and AUTH is only offered after TLS (STARTTLS or port 465) unless KANTOOR_SMTP_ALLOW_PLAINTEXT_AUTH is set. Failures are answered 535 without saying why, a throttled login 454.
  • The envelope sender and every address in the From (and Sender) header must be the address of a mailbox the user may open, else 553 5.7.1. A message needs exactly one From header. Date and Message-ID are added when missing.
  • Extensions: PIPELINING, SIZE (25 MiB by default), 8BITMIME, ENHANCEDSTATUSCODES, STARTTLS, AUTH PLAIN LOGIN. Lines of the message may be 998 bytes, as RFC 5321 says; line endings must be CRLF.
  • Up to 200 messages per user and 400 per client IP per hour, 100 recipients per message; beyond that 450/452.
  • If Karta cannot take the message the answer is 451 (try again later; the client keeps it queued) or, when Karta refused this particular message, 554. Too large is 552.
  • Kantoor does not store a copy: clients save their own in Sent over IMAP. KANTOOR_SMTP_SAVE_SENT=true stores one in the Sent folder as webmail does (it would duplicate the client's own copy).

IMAP

The server advertises exactly what it implements:

IMAP4rev1 LITERAL+ SASL-IR ID ENABLE IDLE NAMESPACE UIDPLUS MOVE UNSELECT
CHILDREN SPECIAL-USE LIST-EXTENDED LIST-STATUS CONDSTORE QRESYNC ESEARCH
SORT THREAD=ORDEREDSUBJECT THREAD=REFERENCES

STARTTLS, LOGINDISABLED and AUTH=PLAIN are added depending on the connection and its TLS state.

  • QRESYNC (RFC 7162): ENABLE QRESYNC, SELECT with QRESYNC, and UID FETCH ... (CHANGEDSINCE n VANISHED) are supported. Expunges are recorded as tombstones so an offline client can resynchronise; a client whose modification sequence is older than the retained tombstone floor is answered with the full set of UIDs that are not visible now.
  • ESEARCH (RFC 4731): SEARCH RETURN (MIN MAX ALL COUNT). SAVE (SEARCHRES) is not supported.
  • SORT (RFC 5256): ordered in SQL over the index, with ARRIVAL, CC, DATE, FROM, SIZE, SUBJECT and TO, and REVERSE. DISPLAYFROM/DISPLAYTO (RFC 5957) are not offered.
  • THREAD (RFC 5256): ORDEREDSUBJECT and REFERENCES, built from the stored Message-ID, References and In-Reply-To headers.

Other limits: the largest APPEND is 25 MiB by default (KANTOOR_IMAP_MAX_MESSAGE_BYTES), the command line is 8 KiB, a non-APPEND literal is 64 KiB, a login must finish within 60 seconds, an idle connection is closed after 30 minutes, and 20 consecutive bad commands or 5 failed logins end the connection.

POP3

POP3 exposes INBOX only. The default delete mode is mark: QUIT adds the keyword $POP3Downloaded and keeps the mail. With KANTOOR_POP3_DELETE_MODE=delete, QUIT expunges what the client marked with DELE. Mail held over quota is invisible to POP3.

A POP3 connection is closed after 10 minutes of idleness.

Connection limits

The defaults are 200 simultaneous connections per protocol and 20 per client IP (an IPv6 client is counted per /64). Both are configurable with KANTOOR_MAIL_MAX_CONNECTIONS and KANTOOR_MAIL_MAX_CONNECTIONS_PER_IP.

If a TCP proxy terminates TLS, set KANTOOR_MAIL_PROXY_TRUSTED to the proxy network and KANTOOR_MAIL_PROXY_TLS=true; Kantoor then reads the real client address from the PROXY protocol header and treats the connection as already encrypted. A peer inside the trusted list must send the header or it is refused. Do not publish the plain listener ports on the host.

Testing the connection

From outside the server, check the certificate and log in:

openssl s_client -connect mail.example.com:993
a1 LOGIN you@example.com <app password>

The app password's last-used address, shown in Settings, App passwords, must be your own address, not a proxy's.